Skip to content

Commit 136ecb7

Browse files
committed
test
1 parent 570dbb3 commit 136ecb7

File tree

11 files changed

+27
-18
lines changed

11 files changed

+27
-18
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ function initiate_upgrade {
354354
rm -rf "${PGDATANEW:?}/"
355355

356356
if [ "$IS_NIX_UPGRADE" = "true" ]; then
357-
LC_ALL=en_US.UTF-8 LC_CTYPE=$SERVER_LC_CTYPE LC_COLLATE=$SERVER_LC_COLLATE LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LOCALE_ARCHIVE=/usr/lib/locale/locale-archive su -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && $PGBINNEW/initdb --encoding=$SERVER_ENCODING --lc-collate=$SERVER_LC_COLLATE --lc-ctype=$SERVER_LC_CTYPE -L $PGSHARENEW -D $PGDATANEW/" -s "$SHELL" postgres
357+
LC_ALL=en_US.UTF-8 LC_CTYPE=$SERVER_LC_CTYPE LC_COLLATE=$SERVER_LC_COLLATE LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LOCALE_ARCHIVE=/usr/lib/locale/locale-archive su -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && $PGBINNEW/initdb --encoding=$SERVER_ENCODING --lc-collate=$SERVER_LC_COLLATE --lc-ctype=$SERVER_LC_CTYPE -L $PGSHARENEW -D $PGDATANEW/ --username=supabase_admin" -s "$SHELL" postgres
358358
else
359-
su -c "$PGBINNEW/initdb -L $PGSHARENEW -D $PGDATANEW/" -s "$SHELL" postgres
359+
su -c "$PGBINNEW/initdb -L $PGSHARENEW -D $PGDATANEW/ --username=supabase_admin" -s "$SHELL" postgres
360360
fi
361361

362362
UPGRADE_COMMAND=$(cat <<EOF

ansible/playbook.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@
104104
loop: "{{ sql_files }}"
105105
when: debpkg_mode or stage2_nix
106106

107+
- name: Create postgres role
108+
become: yes
109+
become_user: postgres
110+
shell:
111+
cmd: /usr/lib/postgresql/bin/psql --username=supabase_admin -d postgres -c "create role postgres superuser login; alter database postgres owner to postgres;"
112+
when: debpkg_mode or stage2_nix
113+
107114
- name: Execute init SQL files
108115
become: yes
109116
become_user: postgres

ansible/tasks/setup-postgres.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@
199199
- name: Initialize the database
200200
become: yes
201201
become_user: postgres
202-
shell: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access"
202+
shell: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access" -o "--username=supabase_admin"
203203
vars:
204204
ansible_command_timeout: 60
205205
when: debpkg_mode
206206

207207
- name: Initialize the database stage2_nix
208208
become: yes
209209
become_user: postgres
210-
shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access"
210+
shell: source /var/lib/postgresql/.bashrc && /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data initdb -o "--allow-group-access" -o "--username=supabase_admin"
211211
args:
212212
executable: /bin/bash
213213
environment:

docker/all-in-one/postgres-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ docker_setup_db() {
226226
docker_setup_env() {
227227
file_env 'POSTGRES_PASSWORD'
228228

229-
file_env 'POSTGRES_USER' 'postgres'
230-
file_env 'POSTGRES_DB' "$POSTGRES_USER"
229+
file_env 'POSTGRES_USER' 'supabase_admin'
230+
file_env 'POSTGRES_DB' 'postgres'
231231
file_env 'POSTGRES_INITDB_ARGS'
232232
: "${POSTGRES_HOST_AUTH_METHOD:=}"
233233

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
flake-utils.lib.eachSystem ourSystems (system:
2222
let
2323
pgsqlDefaultPort = "5435";
24-
pgsqlSuperuser = "postgres";
24+
pgsqlSuperuser = "supabase_admin";
2525
nix2img = nix2container.packages.${system}.nix2container;
2626

2727
# The 'oriole_pkgs' variable holds all the upstream packages in nixpkgs, which
@@ -392,7 +392,7 @@
392392
echo '#!/bin/sh' > $TMPDIR/getkey.sh
393393
echo 'echo $PGSODIUM_KEY' >> $TMPDIR/getkey.sh
394394
chmod +x $TMPDIR/getkey.sh
395-
initdb --locale=C
395+
initdb --locale=C --username=supabase_admin
396396
substitute ${./nix/tests/postgresql.conf.in} $PGDATA/postgresql.conf \
397397
--subst-var-by PGSODIUM_GETKEY_SCRIPT "$TMPDIR/getkey.sh"
398398
echo "listen_addresses = '*'" >> $PGDATA/postgresql.conf

migrations/db/init-scripts/00000000000000-initial-schema.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
create publication supabase_realtime;
66

77
-- Supabase super admin
8-
create user supabase_admin;
98
alter user supabase_admin with superuser createdb createrole replication bypassrls;
109

1110
-- Supabase replication user

nix/docker/init.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
# shellcheck shell=bash
3-
/bin/initdb --locale=C -D /data/postgresql
3+
/bin/initdb --locale=C -D /data/postgresql --username=supabase_admin
44
ln -s /etc/postgresql.conf /data/postgresql/postgresql.conf
55
/bin/postgres -p @PGSQL_DEFAULT_PORT@ -D /data/postgresql

nix/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# shellcheck shell=bash
33

4-
export PGUSER=postgres
4+
export PGUSER=supabase_admin
55
export PGDATA=$PWD/postgres_data
66
export PGHOST=$PWD/postgres
77
export PGPORT=5432

nix/tools/migrate-tool.sh.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ echo "NOTE: using temporary directory $DATDIR for PSQL $1 data, which will not b
5959
echo "NOTE: you are free to re-use this data directory at will"
6060
echo
6161

62-
$OLDVER/bin/initdb -D "$DATDIR" --locale=C
63-
$NEWVER/bin/initdb -D "$NEWDAT" --locale=C
62+
$OLDVER/bin/initdb -D "$DATDIR" --locale=C --username=supabase_admin
63+
$NEWVER/bin/initdb -D "$NEWDAT" --locale=C --username=supabase_admin
6464

6565
# NOTE (aseipp): we need to patch postgresql.conf to have the right pgsodium_getkey script
6666
PSQL_CONF_FILE=@PSQL_CONF_FILE@

nix/tools/run-client-migrate.sh.in

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ MIGRATIONS_DIR=@MIGRATIONS_DIR@
3131
POSTGRESQL_SCHEMA_SQL=@POSTGRESQL_SCHEMA_SQL@
3232
PGBOUNCER_AUTH_SCHEMA_SQL=@PGBOUNCER_AUTH_SCHEMA_SQL@
3333
STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
34-
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -f "$PGBOUNCER_AUTH_SCHEMA_SQL"
35-
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -f "$STAT_EXTENSION_SQL"
34+
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres <<-EOSQL
35+
create role postgres superuser login password '$PGPASSWORD';
36+
alter database postgres owner to postgres;
37+
EOSQL
38+
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$PGBOUNCER_AUTH_SCHEMA_SQL"
39+
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$STAT_EXTENSION_SQL"
3640
for sql in "$MIGRATIONS_DIR"/init-scripts/*.sql; do
3741
echo "$0: running $sql"
3842
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -f "$sql" postgres
@@ -47,4 +51,4 @@ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p "$PORTNO"
4751
# TODO Do we need to reset stats when running migrations locally?
4852
#psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p "$PORTNO" -h localhost -c 'SELECT extensions.pg_stat_statements_reset(); SELECT pg_stat_reset();' postgres || true
4953

50-
exec psql -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost postgres
54+
exec psql -U postgres -p "$PORTNO" -h localhost postgres

0 commit comments

Comments
 (0)