github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_views_and_sequences/run.sh (about) 1 #!/bin/sh 2 # 3 # Copyright 2020 PingCAP, Inc. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 set -eu 17 DB="$TEST_NAME" 18 19 run_sql "create schema $DB;" 20 run_sql "create view $DB.view_1 as select 331 as m;" 21 run_sql "create view $DB.view_2 as select * from $DB.view_1;" 22 run_sql "create sequence $DB.seq_1 nocache cycle maxvalue 40;" 23 run_sql "create table $DB.table_1 (m int primary key default next value for $DB.seq_1, b int);" 24 run_sql "insert into $DB.table_1 (b) values (8), (12), (16), (20);" 25 run_sql "create sequence $DB.seq_2;" 26 run_sql "create table $DB.table_2 (a int default next value for $DB.seq_1, b int default next value for $DB.seq_2, c int);" 27 run_sql "insert into $DB.table_2 (c) values (24), (28), (32);" 28 run_sql "create view $DB.view_3 as select m from $DB.table_1 union select a * b as m from $DB.table_2 union select m from $DB.view_2;" 29 run_sql "drop view $DB.view_1;" 30 run_sql "create view $DB.view_1 as select 133 as m;" 31 32 echo "backup start..." 33 run_br backup db --db "$DB" -s "local://$TEST_DIR/$DB" --pd $PD_ADDR 34 35 run_sql "drop schema $DB;" 36 37 echo "restore start..." 38 run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR 39 40 set -x 41 42 views_count=$(run_sql "select count(*) c, sum(m) s from $DB.view_3;" | tail -2 | paste -sd ';') 43 [ "$views_count" = 'c: 8;s: 181' ] 44 45 run_sql "insert into $DB.table_2 (c) values (33);" 46 seq_val=$(run_sql "select a >= 8 and b >= 4 as g from $DB.table_2 where c = 33;" | tail -1) 47 [ "$seq_val" = 'g: 1' ] 48 49 run_sql "drop schema $DB"