2021-08-01 14:27:44 -07:00
#!/usr/bin/env bash
2021-12-01 12:46:28 +05:30
# Copyright 2021 Collate
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2021-08-01 14:27:44 -07:00
# Resolve links - $0 may be a softlink
PRG = " ${ 0 } "
2022-06-30 10:31:47 +05:30
debug = " $2 "
2023-07-03 19:42:12 +05:30
ignoreFileChecksum = " $3 "
if [ -n " ${ ignoreFileChecksum +x } " ] ; then
ignoreFileChecksum = true
else
ignoreFileChecksum = false
fi
2021-08-01 14:27:44 -07:00
while [ -h " ${ PRG } " ] ; do
ls = ` ls -ld " ${ PRG } " `
link = ` expr " $ls " : '.*-> \(.*\)$' `
if expr " $link " : '/.*' > /dev/null; then
PRG = " $link "
else
PRG = ` dirname " ${ PRG } " ` /" $link "
fi
done
BOOTSTRAP_DIR = ` dirname ${ PRG } `
2021-08-05 10:15:52 +05:30
CONFIG_FILE_PATH = ${ BOOTSTRAP_DIR } /../conf/openmetadata.yaml
2021-08-01 14:27:44 -07:00
SCRIPT_ROOT_DIR = " ${ BOOTSTRAP_DIR } /sql "
# Which java to use
if [ -z " ${ JAVA_HOME } " ] ; then
JAVA = "java"
else
JAVA = " ${ JAVA_HOME } /bin/java "
fi
2022-09-14 23:14:02 -07:00
TABLE_INITIALIZER_MAIN_CLASS = org.openmetadata.service.util.TablesInitializer
2021-12-06 23:28:35 +01:00
LIBS_DIR = " ${ BOOTSTRAP_DIR } " /../libs/
2022-07-05 15:28:59 +05:30
if [ ${ debug } ] ; then
echo $LIBS_DIR
fi
2021-12-06 23:28:35 +01:00
if [ -d " ${ LIBS_DIR } " ] ; then
2021-12-06 21:01:30 -08:00
for file in " ${ LIBS_DIR } " *.jar;
2021-12-06 23:28:35 +01:00
do
CLASSPATH = " $CLASSPATH " :" $file "
done
else
2022-09-14 23:14:02 -07:00
CLASSPATH = ` mvn -pl openmetadata-service -q exec:exec -Dexec.executable= echo -Dexec.args= "%classpath" `
2021-12-06 23:28:35 +01:00
fi
2021-08-01 14:27:44 -07:00
execute( ) {
2022-07-05 15:28:59 +05:30
if [ ${ debug } ] ; then
2021-08-01 14:27:44 -07:00
echo " Using Configuration file: ${ CONFIG_FILE_PATH } "
2022-07-05 15:28:59 +05:30
fi
2023-07-03 19:42:12 +05:30
${ JAVA } -Dbootstrap.dir= $BOOTSTRAP_DIR -cp ${ CLASSPATH } ${ TABLE_INITIALIZER_MAIN_CLASS } -c ${ CONFIG_FILE_PATH } -s ${ SCRIPT_ROOT_DIR } --${ 1 } -ignoreCheckSum ${ ignoreFileChecksum } -${ debug }
2021-08-01 14:27:44 -07:00
}
printUsage( ) {
cat <<-EOF
2023-07-03 19:42:12 +05:30
USAGE: $0 [ create| migrate| info| validate| drop| drop-create| es-drop| es-create| drop-create-all| migrate-all| repair| check-connection| rotate] [ debug] [ ignoreFileChecksum]
2021-08-01 14:27:44 -07:00
create : Creates the tables. The target database should be empty
migrate : Migrates the database to the latest version or creates the tables if the database is empty. Use "info" to see the current version and the pending migrations
info : Shows the list of migrations applied and the pending migration waiting to be applied on the target database
validate : Checks if the all the migrations haven been applied on the target database
drop : Drops all the tables in the target database
2021-12-17 10:53:32 +05:30
drop-create : Drops and recreates all the tables in the target database
2021-12-04 18:54:36 -08:00
es-drop : Drops the indexes in ElasticSearch
es-create : Creates the indexes in ElasticSearch
2021-12-17 10:53:32 +05:30
drop-create-all : Drops and recreates all the tables in the database. Drops and creates all the indexes in ElasticSearch
migrate-all : Migrates the database to the latest version and migrates the indexes in ElasticSearch
repair : Repairs the DATABASE_CHANGE_LOG table which is used to track all the migrations on the target database
2022-01-17 00:31:12 -08:00
This involves removing entries for the failed migrations and update the checksum of migrations already applied on the target database
check-connection : Checks if a connection can be successfully obtained for the target database
2022-02-08 09:50:39 +01:00
rotate : Rotate the Fernet Key defined in $FERNET_KEY
2022-06-30 10:31:47 +05:30
debug : Enable Debugging Mode to get more info
2023-07-03 19:42:12 +05:30
ignoreFileChecksum : Ignore Checksum forces Server Migration for already run migration to be run again
2021-08-01 14:27:44 -07:00
EOF
}
2023-07-03 19:42:12 +05:30
if [ $# -gt 3 ]
2021-08-01 14:27:44 -07:00
then
echo "More than one argument specified, please use only one of the below options"
printUsage
exit 1
fi
opt = " $1 "
case " ${ opt } " in
2022-10-22 04:11:02 +11:00
create | drop | migrate | info | validate | repair | check-connection | es-drop | es-create | rotate)
2021-08-01 14:27:44 -07:00
execute " ${ opt } "
; ;
drop-create )
execute "drop" && execute "create"
; ;
2021-12-04 18:54:36 -08:00
drop-create-all )
execute "drop" && execute "create" && execute "es-drop" && execute "es-create"
; ;
2021-12-16 20:56:58 -08:00
migrate-all )
2023-04-19 09:11:27 +02:00
execute "repair" && execute "migrate" && execute "es-migrate"
2021-12-16 20:56:58 -08:00
; ;
2022-02-08 09:50:39 +01:00
rotate )
execute "rotate"
; ;
2021-08-01 14:27:44 -07:00
*)
printUsage
exit 1
; ;
esac