diff --git a/Dockerfile.migrate b/Dockerfile.migrate index 7f2f789..2c65759 100644 --- a/Dockerfile.migrate +++ b/Dockerfile.migrate @@ -2,6 +2,7 @@ FROM alpine:3.18 ENV PGSERVICEFILE=/tmp/pg_service.conf +ENV PGSERVICE=qwc_configdb ENV ALEMBIC_VERSION=head RUN apk add --no-cache --update postgresql-client py3-alembic py3-psycopg2 diff --git a/README.md b/README.md index 5a73162..10f0c59 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ Migrations will be applied automatically, if necessary, whenever the Docker appl To upgrade to a migration different than `head`, set the `ALEMBIC_VERSION` ENV variable. +By default, the DB specified by the `qwc_configdb` connection will be upgraded. You can specify a different connection by setting the `PGSERVICE` ENV variable. + # Managing an external Config DB You can use an external DB instead of the `qwc-base-db` dockerized DB. diff --git a/alembic.ini b/alembic.ini index 0e04b0b..c8a2e9a 100644 --- a/alembic.ini +++ b/alembic.ini @@ -35,7 +35,7 @@ script_location = alembic # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = postgresql:///?service=qwc_configdb +sqlalchemy.url = postgresql:///?service=%(PGSERVICE)s version_table_schema = qwc_config diff --git a/alembic/env.py b/alembic/env.py index 02c2959..89ebac3 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -2,11 +2,16 @@ from alembic import context from sqlalchemy import engine_from_config, pool from logging.config import fileConfig +import os # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config +# Set variables for config +section = config.config_ini_section +config.set_section_option(section, "PGSERVICE", os.environ.get("PGSERVICE")) + # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) diff --git a/run-migrations.sh b/run-migrations.sh index 0a14eda..059525c 100755 --- a/run-migrations.sh +++ b/run-migrations.sh @@ -5,4 +5,4 @@ until psql service=qwc_configdb -c "select 1" > /dev/null 2>&1; do sleep 1 done -PGSERVICE=qwc_configdb alembic upgrade ${ALEMBIC_VERSION} +alembic upgrade ${ALEMBIC_VERSION}