* 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
This commit is contained in:
shockrah 2021-04-29 21:49:36 -07:00
parent 85660e2fc9
commit 4b47eca257

View File

@ -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