Skip to content

feat: setup supabase_realtime_admin#1852

Open
leandrocp wants to merge 18 commits into
mainfrom
lp-revoke-supabase_realtime_admin
Open

feat: setup supabase_realtime_admin#1852
leandrocp wants to merge 18 commits into
mainfrom
lp-revoke-supabase_realtime_admin

Conversation

@leandrocp
Copy link
Copy Markdown
Contributor

@leandrocp leandrocp commented May 7, 2026

Part of project Migrations v2.

The main change is connecting tenants using supabase_realtime_admin instead of supabase_admin. Related to https://github.com/orgs/supabase/discussions/34270

TLDR:

  • PG 14 is mostly supported running as superuser, see README.md
  • PG 15 up to 15.14.1.015 requires superuser due to a missing supautil grant on realtime.subscription
  • PG >= supabase/postgres:15.14.1.129 can connect and work as supabase_realtime_admin with REPLICATION and supautils managing policies.

The complexity of this PR is because we need to handle existing tenants running with supabase_admin and new projects that should start with supabase_realtime_admin, running from PG14 to 17. This is done mostly by executing the migration setup_supabase_realtime_admin.ex that is gated behind the feature flag use_supabase_realtime_admin (disabled by default).

Review

Start on ## Postgres compatibility in README.md as it sets the expectations and limitations, then schema_test.exs along with changes in tests.yml and integration_tests.yml that shows what is expected to work on each PG version.

Tasks

Closes REAL-25
Closes REAL-377
Closes REAL-527
Closes REAL-630
Closes REAL-778
Closes REAL-781
Closes REAL-816
Closes SEC-562

@coveralls
Copy link
Copy Markdown

coveralls commented May 7, 2026

Coverage Status

Coverage is 91.325%lp-revoke-supabase_realtime_admin into main. No base build found for main.

@leandrocp leandrocp force-pushed the lp-revoke-supabase_realtime_admin branch from d3573fe to 2b98f96 Compare May 12, 2026 12:41
@leandrocp leandrocp changed the title fix: restrict realtime schema feat: setup supabase_realtime_admin May 12, 2026
@leandrocp leandrocp force-pushed the lp-revoke-supabase_realtime_admin branch 3 times, most recently from 72e61c1 to c3a692e Compare May 12, 2026 15:11
Comment thread .github/workflows/tests.yml Outdated
name: Tests PG15 (Partition ${{ matrix.partition }})
runs-on: blacksmith-8vcpu-ubuntu-2404
env:
POSTGRES_IMAGE: supabase/postgres:15.14.1.113
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimum PG15 version that grants policy on realtime.subscription via supautils.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous function required grant usage because of ::regclass casting, see test "subscription works when role lacks usage permission".

@leandrocp leandrocp force-pushed the lp-revoke-supabase_realtime_admin branch from c3a692e to 9353942 Compare May 12, 2026 15:39
Comment thread priv/repo/dev_seeds.exs
_ -> raise "Running Migrations failed"
end

Tenants.Migrations.run_migrations(tenant)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant so I removed it but not sure about this change.

Comment thread test/realtime/extensions/cdc_rls/cdc_rls_test.exs
Comment thread .github/workflows/tests.yml Outdated
name: coverage-partition-${{ matrix.partition }}
path: cover/lcov.info

tests-pg15:
Copy link
Copy Markdown
Contributor Author

@leandrocp leandrocp May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could execute this test only on main or when some specific files changes if running on every branch is too expensive.

Copy link
Copy Markdown
Contributor Author

@leandrocp leandrocp May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test module to verify permissions, ie: restrict what must be restricted without breaking the system.

Comment thread test/support/containers.ex
@blacksmith-sh

This comment has been minimized.

Copy link
Copy Markdown
Member

@edgurgel edgurgel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests on schema_test.exs

@blacksmith-sh

This comment has been minimized.


case Postgrex.query(conn, query, []) do
{:ok, _} -> Logger.debug("Partition #{partition_name} created")
alter_owner = "ALTER TABLE realtime.#{partition_name} OWNER TO supabase_realtime_admin"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh so we always need to change this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and also new objects created through migrations (sorry I forgot to mention this). The reason is because we can't switch to supabase_realtime_admin on all projects, really only supabase/postgres >= 15.14.1.018 will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants