vitess.io/vitess@v0.16.2/examples/compose/schemaload.sh (about) 1 #!/bin/bash -e 2 3 # Copyright 2020 The Vitess Authors. 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 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 sleeptime=${SLEEPTIME:-0} 18 targettab=${TARGETTAB:-"${CELL}-0000000101"} 19 schema_files=${SCHEMA_FILES:-'create_messages.sql create_tokens.sql'} 20 vschema_file=${VSCHEMA_FILE:-'default_vschema.json'} 21 load_file=${POST_LOAD_FILE:-''} 22 external_db=${EXTERNAL_DB:-'0'} 23 export PATH=/vt/bin:$PATH 24 25 sleep $sleeptime 26 27 if [ ! -f schema_run ]; then 28 while true; do 29 vtctlclient --server vtctld:$GRPC_PORT GetTablet $targettab && break 30 sleep 1 31 done 32 if [ "$external_db" = "0" ]; then 33 for schema_file in $schema_files; do 34 echo "Applying Schema ${schema_file} to ${KEYSPACE}" 35 vtctlclient --server vtctld:$GRPC_PORT -- ApplySchema --sql-file /script/tables/${schema_file} $KEYSPACE || \ 36 vtctlclient --server vtctld:$GRPC_PORT -- ApplySchema --sql "$(cat /script/tables/${schema_file})" $KEYSPACE || true 37 done 38 fi 39 echo "Applying VSchema ${vschema_file} to ${KEYSPACE}" 40 41 vtctlclient --server vtctld:$GRPC_PORT -- ApplyVSchema --vschema_file /script/${vschema_file} $KEYSPACE || \ 42 vtctlclient --server vtctld:$GRPC_PORT -- ApplyVSchema --vschema "$(cat /script/${vschema_file})" $KEYSPACE 43 44 echo "List All Tablets" 45 vtctlclient --server vtctld:$GRPC_PORT ListAllTablets 46 47 if [ -n "$load_file" ]; then 48 # vtgate can take a REALLY long time to come up fully 49 sleep 60 50 mysql --port=15306 --host=vtgate < /script/$load_file 51 fi 52 53 touch /vt/schema_run 54 echo "Time: $(date). SchemaLoad completed at $(date "+%FT%T") " >> /vt/schema_run 55 echo "Done Loading Schema at $(date "+%FT%T")" 56 fi