feat(cloudflare): local plugin-replica worker with Postgres read subscriber#2619
feat(cloudflare): local plugin-replica worker with Postgres read subscriber#2619riderx wants to merge 2 commits into
Conversation
…riber Introduce a plugin-replica worker stack that boots a local Postgres container, applies the read-replica schema, subscribes to Supabase logical replication, and routes read-only plugin queries through LOCAL_READ_REPLICA_DB_URL. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Replace invalid [db.config] keys that broke Supabase CLI config parsing in CI. Co-authored-by: Cursor <cursoragent@cursor.com>
|
| container_name: capgo_plugin_read_replica | ||
| environment: | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres |
RobinWitch
left a comment
There was a problem hiding this comment.
read_replicate/common.sh currently embeds a literal 0x01 byte in the sed replacement at apply_local_subscription_source_connection, not the \1 capture-group reference.
That means the local replica path rewrites a valid source URL such as postgresql://postgres:postgres@127.0.0.1:54322/postgres?... into a URL whose password is the control character (postgresql://postgres:<0x01>@...). The next psql "$SOURCE_DB_URL" calls in replicate_setup_source.sh / replicate_to_replica.sh then authenticate with the wrong password, so bun run readreplicate:local and bun run plugin-replica:dev fail before the publication/subscription setup can run.
The extraction above uses \1, so this line should do the same instead of storing the literal control byte.
|
Closing: superseded by colo-cache + targeted invalidation approach (new PR incoming). |




Summary (AI generated)
cloudflare_workers/plugin-replica/worker that reuses the existing plugin routesread_replicate/schema_replicate.sqland subscribes to local Supabase logical replicationLOCAL_READ_REPLICA_DB_URLrouting inpg.tsso read-only plugin queries hit the local replicabun run plugin-replica:devorchestration script and local replication helpers inread_replicate/Motivation (AI generated)
Local Cloudflare plugin testing currently hits the primary Supabase database directly, while production plugin workers read from regional Postgres replicas. This change mirrors production read-replica behavior locally so plugin hot paths can be exercised against a subscriber database.
Business Impact (AI generated)
Improves local and CI fidelity for
/updates,/stats, and/channel_selfwithout changing production behavior. Reduces risk of shipping plugin changes that work on primary DB but fail on read replicas.Test Plan (AI generated)
bun run supabase:start && bun run supabase:db:resetbun run plugin-replica:devand verify worker responds onhttp://127.0.0.1:8790/okX-Database-Source: LOCAL_READ_REPLICAbunx vitest run tests/pg-local-read-replica.unit.test.tsGenerated with AI
Made with Cursor