Skip to content

Commit

Permalink
Allow specifying PGSERVICE to migrate as ENV-var
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jun 12, 2024
1 parent 478c51e commit 337468c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dockerfile.migrate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion run-migrations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 337468c

Please sign in to comment.