CirclesUBI/api-server

Drift between migrations container and source manifests

almereyda opened this issue · 1 comments

Describe the bug

The api-server migrations declared in

- "src/api-db-migrations/**"

and executed in

COPY ./src/api-db-migrations/ /docker-entrypoint-initdb.d/

are manually prepared for their execution environment

envsubst < /docker-entrypoint-initdb.d/0.1.504-fix1.sql > /docker-entrypoint-initdb.d/0.1.504-fix1.envsubst
mv /docker-entrypoint-initdb.d/0.1.504-fix1.envsubst /docker-entrypoint-initdb.d/0.1.504-fix1.sql
ls /docker-entrypoint-initdb.d/*.sql | xargs -I% sh -c 'psql $\{CONNECTION_STRING_ROOT\} < %'

and would not pick up newer migrations, which are not explicitly cared for in Dockerfile.migrations. This is in contrast to the initialisation container of the local development environment, which improves on this with dynamically replacing environmental variables within https://github.com/CirclesUBI/land-local/blob/3cb9f3085b63d584eb63667723bdc35821c31fab/modules/api-db-init/seed.sh#L18

ls src/api-db-migrations/*.sql | xargs -I% sh -c 'psql ${CONNECTION_STRING_ROOT} << envsubst < %'

Additionally, a recent changes in the code have led to some drift between the migrations container and its source SQL declarations, which results in all 0.1.504-fix1 rules not to be applied anymore.

To Reproduce

Steps to reproduce the behavior:

  1. Set up a clean deployment environment for api-server. Take example in the workload-*-api-server manifests.
  2. Let the cluster reconciliate the database migrations into the database.
  3. Find all statements from 0.1.504-fix1 missing in the logs of the initialisation container.
    api-server-migrations.txt

Expected behavior

All migrations are loaded when initialising a database from them.

Additional context

We can consider this Dockerfile here as a base layer for the fixture installation in land-local.

Resolved.