From 4b47eca25798a79cef06b9ed7f85635c02ea3c4e Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 29 Apr 2021 21:49:36 -0700 Subject: [PATCH] * Fixing pathing on migrations directory * Moving all sql logs to their own log file to avoid cluttering stdout with things that aren't relevant to the immediate goal here --- scripts/build-db.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/build-db.sh b/scripts/build-db.sh index 837dd86..79b40fb 100644 --- a/scripts/build-db.sh +++ b/scripts/build-db.sh @@ -20,6 +20,9 @@ if [ ! $2 ];then exit 1 fi +# Log paths +migration_logs=sql-migration.log + migration_loc=$1 env_path=$2 @@ -49,17 +52,20 @@ if [ ! $DATABASE_PORT ];then fi # Next we setup the database user -mysql -e "CREATE USER '$DATABASE_USER'@'$DATABASE_HOST' IDENTIFIED BY '$DATABASE_PASS';" +mysql -e "CREATE USER '$DATABASE_USER'@'$DATABASE_HOST' IDENTIFIED BY '$DATABASE_PASS';" \ + > $migration_logs 2>&1 # Yet another reason to not use this in prod to setup you're database -mysql -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'$DATABASE_HOST';" +mysql -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'$DATABASE_HOST';" \ + >> $migration_logs 2>&1 # First we'll setup the databse that we want to use for dir in $(ls $migration_loc);do # Port field is ignored in this script as its straight up not used in Docker tests - echo Migrating $dir - mysql -u $DATABASE_USER -p $DATABASE_PASS \ + # NOTE: there should **not** be a space between -p and the database password + echo Migrating $migration_loc/$dir + mysql -u $DATABASE_USER -p$DATABASE_PASS \ -h $DATABASE_HOST -D $DATABASE_NAME \ - < $dir/up.sql + < $migration_loc/$dir/up.sql >> $migration_logs 2>&1 done