From 1db773e68e50f333369ccde727166805bce2b795 Mon Sep 17 00:00:00 2001 From: Mandeep Khinda Date: Thu, 5 Apr 2018 18:26:07 +0000 Subject: Removing portal schema from configmap -Trying a new way to initialize maria db's. -Docker image contains project sources and sql files are fetched and executed agains't the target database. -duplicates are silently ignored. -A script that takes some basic params will do the heavy lifting -A 2nd job to make some OOM specific changes (carry over from amsterdam) -docker image has been pushed to oomk8s under the 2.0.0 number Issue-ID: OOM-858 Change-Id: I56d0c9c5aa1d3c4a9df2998634b9147db626d1fb Signed-off-by: Mandeep Khinda --- .../docker/init/mariadb-client/db_migrate.sh | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 kubernetes/portal/docker/init/mariadb-client/db_migrate.sh (limited to 'kubernetes/portal/docker/init/mariadb-client/db_migrate.sh') diff --git a/kubernetes/portal/docker/init/mariadb-client/db_migrate.sh b/kubernetes/portal/docker/init/mariadb-client/db_migrate.sh new file mode 100644 index 0000000000..32a634a9e5 --- /dev/null +++ b/kubernetes/portal/docker/init/mariadb-client/db_migrate.sh @@ -0,0 +1,23 @@ +#!/bin/sh -x +SQL_DEST_DIR=${SQL_DEST_DIR:-/tmp/sql} +DB_PORT=${DB_PORT:-3306} + +[[ -z "$SQL_SRC_DIR" ]] && { echo "Error: SQL_SRC_DIR must be provided as an environment variable"; exit 1; } +[[ -z "$DB_USER" ]] && { echo "Error: DB_USER must be provided as an environment variable"; exit 1; } +[[ -z "$DB_PASS" ]] && { echo "Error: DB_PASS must be provided as an environment variable"; exit 1; } +[[ -z "$DB_HOST" ]] && { echo "Error: DB_HOST must be provided as an environment variable"; exit 1; } + +mkdir -p $SQL_DEST_DIR + +#Find all sql files and copy them to the destination directory +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])) }' + + +#Not needed right now? +#--database=$DB_NAME + +#--force to deal with duplicate records in absense of "insert ignore" +##ERROR 1062 (23000) at line 382: Duplicate entry '2' for key 'PRIMARY' + +cd $SQL_DEST_DIR +cat *.sql | mysql -vv --user=$DB_USER --password=$DB_PASS --host=$DB_HOST --port=$DB_PORT --force -- cgit 1.2.3-korg