Skip to content

init-runtime-role.sh aborts every first start: psql -c does not expand :'owner' #102

Closed

Description

@brettheap

Summary. The migration-owner guard passes a psql variable inside psql -c, which psql does not interpolate, so the server gets a literal : and the script exits 1 on every fresh data volume. On the next restart the entrypoint skips init and Postgres comes up healthy without the runtime role.

Reproduce (v0.1.0 and main at c94878b, postgres:16 = 16.16):

git clone https://github.com/opensoft/openDox-code && cd openDox-code
docker compose --env-file deploy/compose/.env.example \
  -f deploy/compose/docker-compose.yaml up postgres

Observed (container exits 1; the message wrongly says the existing owner is missing):

ERROR:  syntax error at or near ":"
LINE 1: select 1 from pg_roles where rolname = :'owner'
init-runtime-role: OPENDOX_MIGRATION_PG_USER names 'opendox', which this database does not have. …

restart: unless-stopped restarts it. The second start logs "Skipping initialization" and is healthy, but psql -U opendox_runtime fails with role "opendox_runtime" does not exist.

Expected. The guard finds the existing owner, and the role and grants are created.

Where. deploy/compose/init-runtime-role.sh:80-82 and the byte-identical deploy/kubernetes/base/init-runtime-role.sh:80-82. They are mounted at docker-compose.yaml:61 and postgres-statefulset.yaml:125-127. Introduced with #25 (2026-09-18), unchanged in v0.1.0.

Impact.

  • Every new bundled-Postgres install with default settings (compose and the kubernetes base).
  • The runtime role is never created, and init is not retried unless the volume is wiped.
  • CI misses it. tests_runtime/test_deploy_shape.py only reads the script as text (111 pass with the bug), and the validate job's postgres:16 service container never mounts the script.

Suggested fix (both copies):

-if ! psql -tAqX --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" \
-      -v owner="$migration_owner" \
-      -c "select 1 from pg_roles where rolname = :'owner'" | grep -q '^1$'; then
+if ! printf '%s\n' "select 1 from pg_roles where rolname = :'owner'" |
+     psql -tAqX --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" \
+          -v owner="$migration_owner" | grep -q '^1$'; then

Checked locally with this change: init completes, the runtime role gets CONNECT, schema USAGE and default DML privileges, a named-but-missing owner still gets the intended refusal, and the existing shape tests still pass. A regression test should run the script against a real postgres:16.

Notes. Reproduced in Docker only (compose end to end, and a container with the Kubernetes pod's settings); not run on a cluster. Draft PR #99 edits both copies of this script but not these lines.

🤖 Generated with Claude Code

Activity

  1. added a commit that references this issue on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions