Removing portal schema from configmap
[oom.git] / kubernetes / portal / docker / init / mariadb-client / db_migrate.sh
1 #!/bin/sh -x
2 SQL_DEST_DIR=${SQL_DEST_DIR:-/tmp/sql}
3 DB_PORT=${DB_PORT:-3306}
4
5 [[ -z "$SQL_SRC_DIR" ]] && { echo "Error: SQL_SRC_DIR must be provided as an environment variable"; exit 1; }
6 [[ -z "$DB_USER" ]] && { echo "Error: DB_USER must be provided as an environment variable"; exit 1; }
7 [[ -z "$DB_PASS" ]] && { echo "Error: DB_PASS must be provided as an environment variable"; exit 1; }
8 [[ -z "$DB_HOST" ]] && { echo "Error: DB_HOST must be provided as an environment variable"; exit 1; }
9
10 mkdir -p $SQL_DEST_DIR
11
12 #Find all sql files and copy them to the destination directory
13 find "/onap-sources/$SQL_SRC_DIR" -type f -iname "*.sql" | awk -v dest="$SQL_DEST_DIR" '{n=split($1,a,"/"); system(sprintf( "cp %s %s", $1, dest"/"a[n])) }'
14
15
16 #Not needed right now?
17 #--database=$DB_NAME
18
19 #--force to deal with duplicate records in absense of "insert ignore"
20 ##ERROR 1062 (23000) at line 382: Duplicate entry '2' for key 'PRIMARY'
21
22 cd $SQL_DEST_DIR
23 cat *.sql | mysql -vv --user=$DB_USER --password=$DB_PASS --host=$DB_HOST --port=$DB_PORT --force