Skip to content

fix: evtrigs ownership #1488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ nix run github:supabase/postgres/mybranch#dbmate-tool -- --version 15

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)



## How it was Created

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

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

1. Run all `db/init-scripts` with `postgres` superuser role.
2. Run all `db/migrations` with `supabase_admin` superuser role.
3. Finalize role passwords with `/etc/postgresql.schema.sql` if present.
1. Run all `db/migrations` with `supabase_admin` superuser role.
2. Finalize role passwords with `/etc/postgresql.schema.sql` if present.

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.

Expand Down
7 changes: 0 additions & 7 deletions migrations/db/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ begin
end if;
end \$\$
EOSQL
# run init scripts as postgres user
for sql in "$db"/init-scripts/*.sql; do
echo "$0: running $sql"
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -f "$sql"
done
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"
# run migrations as super user - postgres user demoted in post-setup
for sql in "$db"/migrations/*.sql; do
Expand All @@ -54,8 +49,6 @@ else
create role postgres superuser login password '$PGPASSWORD';
alter database postgres owner to postgres;
EOSQL
# run init scripts as postgres user
DBMATE_MIGRATIONS_DIR="$db/init-scripts" DATABASE_URL="postgres://postgres:$connect" dbmate --no-dump-schema migrate
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"
# run migrations as super user - postgres user demoted in post-setup
DBMATE_MIGRATIONS_DIR="$db/migrations" DATABASE_URL="postgres://supabase_admin:$connect" dbmate --no-dump-schema migrate
Expand Down
1 change: 0 additions & 1 deletion migrations/tests/extensions/04-pg_cron.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ BEGIN;
-- create cron extension as supabase_admin
create extension if not exists pg_cron;

-- \ir migrations/db/init-scripts/00000000000003-post-setup.sql
grant usage on schema cron to postgres with grant option;
alter default privileges in schema cron grant all on tables to postgres with grant option;
alter default privileges in schema cron grant all on routines to postgres with grant option;
Expand Down
1 change: 0 additions & 1 deletion migrations/tests/extensions/15-pg_net.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ BEGIN;
-- create net extension as supabase_admin
create extension if not exists pg_net with schema "extensions";

-- \ir migrations/db/init-scripts/00000000000003-post-setup.sql
grant usage on schema net TO postgres, anon, authenticated, service_role;
alter function net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) security definer;
alter function net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) security definer;
Expand Down
13 changes: 13 additions & 0 deletions nix/tests/expected/evtrigs.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
select proname, proowner::regrole from pg_proc where prorettype = 'event_trigger'::regtype;
proname | proowner
--------------------------+----------------
event_trigger_in | supabase_admin
pgrst_drop_watch | supabase_admin
grant_pg_graphql_access | supabase_admin
set_graphql_placeholder | supabase_admin
pgrst_ddl_watch | supabase_admin
increment_schema_version | supabase_admin
grant_pg_cron_access | supabase_admin
grant_pg_net_access | supabase_admin
(8 rows)

1 change: 1 addition & 0 deletions nix/tests/sql/evtrigs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select proname, proowner::regrole from pg_proc where prorettype = 'event_trigger'::regtype;
5 changes: 0 additions & 5 deletions nix/tools/dbmate-tool.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ EOSQL
export DATABASE_URL="postgres://$PGSQL_USER:$PGPASSWORD@localhost:$PORTNO/postgres?sslmode=disable"
# Export path so dbmate can find correct psql and pg_dump
export PATH="$PSQLBIN:$PATH"
# Run init scripts
if ! dbmate --migrations-dir "$MIGRATIONS_DIR/init-scripts" up; then
echo "Error: Initial migration failed"
exit 1
fi

# Password update command
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
Expand Down
8 changes: 0 additions & 8 deletions nix/tools/run-server.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,6 @@ EOSQL
'stop_postgres' 1
fi
else
# Run default init scripts
for sql in "$MIGRATIONS_DIR"/init-scripts/*.sql; do
echo "Running $sql"
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PSQL_USER" -p "$PORTNO" -h localhost -f "$sql" postgres; then
'stop_postgres' 1
fi
done

# Set superuser password
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
'stop_postgres' 1
Expand Down
Loading