diff --git a/data/migrations/migration.sh b/data/migrations/migration.sh index e78547dfb..19c8df4a3 100755 --- a/data/migrations/migration.sh +++ b/data/migrations/migration.sh @@ -1,6 +1,7 @@ set -e -DOCKER_IP=`echo $DOCKER_HOST | sed 's/tcp:\/\///' | sed 's/:.*//'` +PARSED_DOCKER_HOST=`echo $DOCKER_HOST | sed 's/tcp:\/\///' | sed 's/:.*//'` +DOCKER_IP="${PARSED_DOCKER_HOST:-127.0.0.1}" MYSQL_CONFIG_OVERRIDE="{\"DB_URI\":\"mysql+pymysql://root:password@$DOCKER_IP/genschema\"}" PERCONA_CONFIG_OVERRIDE="{\"DB_URI\":\"mysql+pymysql://root:password@$DOCKER_IP/genschema\"}" PGSQL_CONFIG_OVERRIDE="{\"DB_URI\":\"postgresql://postgres@$DOCKER_IP/genschema\"}" @@ -74,18 +75,21 @@ down_postgres() { } gen_migrate() { - # Generate a SQLite database with the schema as defined by the existing alembic model. + # Generate a database with the schema as defined by the existing alembic model. QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic upgrade head + # Generate the migration to the current model. QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic revision --autogenerate -m "$2" } test_migrate() { - # Generate a SQLite database with the schema as defined by the existing alembic model. + # Generate a database with the schema as defined by the existing alembic model. + echo '> Running upgrade' QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic upgrade head # Downgrade to verify it works in both directions. + echo '> Running downgrade' COUNT=`ls data/migrations/versions/*.py | wc -l | tr -d ' '` QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic downgrade "-$COUNT" }