Merge "[UUI] Service Mesh Compliance for UUI"
[oom.git] / kubernetes / portal / docker / init / mariadb-client / db_migrate.sh
1 #!/bin/sh -x
2
3 # Copyright © 2018 Amdocs, Bell Canada, AT&T
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 SQL_DEST_DIR=${SQL_DEST_DIR:-/tmp/sql}
18 DB_PORT=${DB_PORT:-3306}
19
20 [ -z "$SQL_SRC_DIR" ] && { echo "Error: SQL_SRC_DIR must be provided as an environment variable"; exit 1; }
21 [ -z "$DB_USER" ] && { echo "Error: DB_USER must be provided as an environment variable"; exit 1; }
22 [ -z "$DB_PASS" ] && { echo "Error: DB_PASS must be provided as an environment variable"; exit 1; }
23 [ -z "$DB_HOST" ] && { echo "Error: DB_HOST must be provided as an environment variable"; exit 1; }
24
25 mkdir -p $SQL_DEST_DIR
26
27 #Find all sql files and copy them to the destination directory
28 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])) }'
29
30
31 #Not needed right now?
32 #--database=$DB_NAME
33
34 #--force to deal with duplicate records in absense of "insert ignore"
35 ##ERROR 1062 (23000) at line 382: Duplicate entry '2' for key 'PRIMARY'
36
37 cd $SQL_DEST_DIR
38 cat *.sql | mysql -vv --user=$DB_USER --password=$DB_PASS --host=$DB_HOST --port=$DB_PORT --force