@@ -145,10 +145,13 @@ RUN sed -i \
145145 -e "s|#unix_socket_directories = '/tmp'|unix_socket_directories = '/var/run/postgresql'|g" \
146146 -e "s|#session_preload_libraries = ''|session_preload_libraries = 'supautils'|g" \
147147 -e "s|#include = '/etc/postgresql-custom/supautils.conf'|include = '/etc/postgresql-custom/supautils.conf'|g" \
148- -e "s|#include = '/etc/postgresql-custom/wal-g.conf'|include = '/etc/postgresql-custom/wal-g.conf'|g" \
148+ # skip wal-g - unused by multigres
149+ # -e "s|#include = '/etc/postgresql-custom/wal-g.conf'|include = '/etc/postgresql-custom/wal-g.conf'|g" \
149150 -e "s/ timescaledb,//g" \
150151 -e "s/ pgsodium,//g" \
151152 -e "s/db_user_namespace = off/#db_user_namespace = off/g" \
153+ # skip - managed by pgctld
154+ -e "s|^data_directory |#data_directory |g" \
152155 /etc/postgresql/postgresql.conf && \
153156 echo "pgsodium.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
154157 echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
@@ -203,6 +206,25 @@ RUN printf '#!/bin/sh\nexec /nix/var/nix/profiles/default/bin/pgctld --postgres-
203206# Strip extensions absent from pg17 vanilla build
204207RUN sed -i 's/ timescaledb,//g; s/ plv8,//g' /etc/postgresql-custom/supautils.conf
205208
209+ # Generate a single SQL manifest that pgctld runs via --init-db-sql-file after initdb.
210+ # Creates the postgres role, runs init-scripts as postgres (matching migrate.sh),
211+ # then runs migrations as supabase_admin.
212+ RUN set -e && \
213+ manifest=/docker-entrypoint-initdb.d/multigres-init.sql && \
214+ printf -- "-- Auto-generated: run init-scripts and migrations after initdb\n" > "$manifest" && \
215+ printf "DO \$\$ BEGIN\n IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'postgres') THEN\n CREATE ROLE postgres SUPERUSER LOGIN;\n END IF;\nEND \$\$;\n" >> "$manifest" && \
216+ printf "ALTER DATABASE postgres OWNER TO postgres;\n\n" >> "$manifest" && \
217+ printf "SET SESSION AUTHORIZATION postgres;\n" >> "$manifest" && \
218+ for f in $(ls /docker-entrypoint-initdb.d/init-scripts/*.sql 2>/dev/null | sort); do \
219+ printf '\\ir init-scripts/%s\n' "$(basename "$f")" >> "$manifest"; \
220+ done && \
221+ printf "\nRESET SESSION AUTHORIZATION;\n\n" >> "$manifest" && \
222+ for f in $(ls /docker-entrypoint-initdb.d/migrations/*.sql 2>/dev/null | sort); do \
223+ printf '\\ir migrations/%s\n' "$(basename "$f")" >> "$manifest"; \
224+ done && \
225+ chown postgres:postgres "$manifest"
226+
227+ ENV POSTGRES_INITDB_SQL_FILES=/docker-entrypoint-initdb.d/multigres-init.sql
206228ENV PATH="/nix/var/nix/profiles/default/bin:/usr/lib/postgresql/bin:${PATH}"
207229ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive
208230
@@ -267,6 +289,23 @@ RUN printf '#!/bin/sh\nexec /nix/var/nix/profiles/default/bin/pgctld --postgres-
267289 > /usr/local/bin/pgctld && \
268290 chmod +x /usr/local/bin/pgctld
269291
292+ # Regenerate manifest after orioledb added 00-pre-init.sql to init-scripts/
293+ RUN set -e && \
294+ manifest=/docker-entrypoint-initdb.d/multigres-init.sql && \
295+ printf -- "-- Auto-generated: run init-scripts and migrations after initdb\n" > "$manifest" && \
296+ printf "DO \$\$ BEGIN\n IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'postgres') THEN\n CREATE ROLE postgres SUPERUSER LOGIN;\n END IF;\nEND \$\$;\n" >> "$manifest" && \
297+ printf "ALTER DATABASE postgres OWNER TO postgres;\n\n" >> "$manifest" && \
298+ printf "SET SESSION AUTHORIZATION postgres;\n" >> "$manifest" && \
299+ for f in $(ls /docker-entrypoint-initdb.d/init-scripts/*.sql 2>/dev/null | sort); do \
300+ printf '\\ir init-scripts/%s\n' "$(basename "$f")" >> "$manifest"; \
301+ done && \
302+ printf "\nRESET SESSION AUTHORIZATION;\n\n" >> "$manifest" && \
303+ for f in $(ls /docker-entrypoint-initdb.d/migrations/*.sql 2>/dev/null | sort); do \
304+ printf '\\ir migrations/%s\n' "$(basename "$f")" >> "$manifest"; \
305+ done && \
306+ chown postgres:postgres "$manifest"
307+
308+ ENV POSTGRES_INITDB_SQL_FILES=/docker-entrypoint-initdb.d/multigres-init.sql
270309ENV PATH="/nix/var/nix/profiles/default/bin:/usr/lib/postgresql/bin:${PATH}"
271310ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive
272311
0 commit comments