Skip to content

Commit 10912b9

Browse files
committed
fix: evtrigs ownership
Fixes #1437 (comment). Moves migrations/db/init-scripts to migrations/db/migrations.
1 parent 5b1b1f4 commit 10912b9

12 files changed

+16
-27
lines changed

migrations/README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ nix run github:supabase/postgres/mybranch#dbmate-tool -- --version 15
4242

4343
aiming to provide a single source of truth for migrations on the platform that can be depended upon by those components. For more information on goals see [the RFC](https://www.notion.so/supabase/Centralize-SQL-Migrations-cd3847ae027d4f2bba9defb2cc82f69a)
4444

45-
46-
4745
## How it was Created
4846

4947
Migrations were pulled (in order) from:
@@ -53,9 +51,8 @@ Migrations were pulled (in order) from:
5351

5452
For compatibility with hosted projects, we include [migrate.sh](migrate.sh) that executes migrations in the same order as ami build:
5553

56-
1. Run all `db/init-scripts` with `postgres` superuser role.
57-
2. Run all `db/migrations` with `supabase_admin` superuser role.
58-
3. Finalize role passwords with `/etc/postgresql.schema.sql` if present.
54+
1. Run all `db/migrations` with `supabase_admin` superuser role.
55+
2. Finalize role passwords with `/etc/postgresql.schema.sql` if present.
5956

6057
Additionally, [supabase/postgres](https://github.com/supabase/postgres/blob/develop/ansible/playbook-docker.yml#L9) image contains several migration scripts to configure default extensions. These are run first by docker entrypoint and included in ami by ansible.
6158

migrations/db/migrate.sh

-7
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ begin
3838
end if;
3939
end \$\$
4040
EOSQL
41-
# run init scripts as postgres user
42-
for sql in "$db"/init-scripts/*.sql; do
43-
echo "$0: running $sql"
44-
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -f "$sql"
45-
done
4641
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"
4742
# run migrations as super user - postgres user demoted in post-setup
4843
for sql in "$db"/migrations/*.sql; do
@@ -54,8 +49,6 @@ else
5449
create role postgres superuser login password '$PGPASSWORD';
5550
alter database postgres owner to postgres;
5651
EOSQL
57-
# run init scripts as postgres user
58-
DBMATE_MIGRATIONS_DIR="$db/init-scripts" DATABASE_URL="postgres://postgres:$connect" dbmate --no-dump-schema migrate
5952
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"
6053
# run migrations as super user - postgres user demoted in post-setup
6154
DBMATE_MIGRATIONS_DIR="$db/migrations" DATABASE_URL="postgres://supabase_admin:$connect" dbmate --no-dump-schema migrate

migrations/tests/extensions/04-pg_cron.sql

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ BEGIN;
22
-- create cron extension as supabase_admin
33
create extension if not exists pg_cron;
44

5-
-- \ir migrations/db/init-scripts/00000000000003-post-setup.sql
65
grant usage on schema cron to postgres with grant option;
76
alter default privileges in schema cron grant all on tables to postgres with grant option;
87
alter default privileges in schema cron grant all on routines to postgres with grant option;

migrations/tests/extensions/15-pg_net.sql

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ BEGIN;
22
-- create net extension as supabase_admin
33
create extension if not exists pg_net with schema "extensions";
44

5-
-- \ir migrations/db/init-scripts/00000000000003-post-setup.sql
65
grant usage on schema net TO postgres, anon, authenticated, service_role;
76
alter function net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) security definer;
87
alter function net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) security definer;

nix/tests/expected/evtrigs.out

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
select proname, proowner::regrole from pg_proc where prorettype = 'event_trigger'::regtype;
2+
proname | proowner
3+
--------------------------+----------------
4+
event_trigger_in | supabase_admin
5+
pgrst_drop_watch | supabase_admin
6+
grant_pg_graphql_access | supabase_admin
7+
set_graphql_placeholder | supabase_admin
8+
pgrst_ddl_watch | supabase_admin
9+
increment_schema_version | supabase_admin
10+
grant_pg_cron_access | supabase_admin
11+
grant_pg_net_access | supabase_admin
12+
(8 rows)
13+

nix/tests/sql/evtrigs.sql

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select proname, proowner::regrole from pg_proc where prorettype = 'event_trigger'::regtype;

nix/tools/dbmate-tool.sh.in

-5
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,6 @@ EOSQL
243243
export DATABASE_URL="postgres://$PGSQL_USER:$PGPASSWORD@localhost:$PORTNO/postgres?sslmode=disable"
244244
# Export path so dbmate can find correct psql and pg_dump
245245
export PATH="$PSQLBIN:$PATH"
246-
# Run init scripts
247-
if ! dbmate --migrations-dir "$MIGRATIONS_DIR/init-scripts" up; then
248-
echo "Error: Initial migration failed"
249-
exit 1
250-
fi
251246

252247
# Password update command
253248
if ! "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"; then

nix/tools/run-server.sh.in

-8
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,6 @@ EOSQL
309309
'stop_postgres' 1
310310
fi
311311
else
312-
# Run default init scripts
313-
for sql in "$MIGRATIONS_DIR"/init-scripts/*.sql; do
314-
echo "Running $sql"
315-
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PSQL_USER" -p "$PORTNO" -h localhost -f "$sql" postgres; then
316-
'stop_postgres' 1
317-
fi
318-
done
319-
320312
# Set superuser password
321313
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PSQL_USER" -p "$PORTNO" -h localhost -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"; then
322314
'stop_postgres' 1

0 commit comments

Comments
 (0)