Skip to content

fix: wait for tenant migrations before creating postgres changes subscriptions - #2458

Merged
leandrocp merged 4 commits into
mainfrom
feat/wait-migrations-before-pg-changes
Nov 4, 2026
Merged

leandrocp merged 4 commits into
mainfrom
feat/wait-migrations-before-pg-changes

Conversation

@leandrocp

@leandrocp leandrocp commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Postgres Changes could subscribe before Connect ran the tenant's migrations, so new code hit the old schema (42883 errors from #2097 on staging).

Connect now reports migrations_ran in its syn metadata, and SubscriptionManager waits for it before publishing itself. Until then channels get {:error, :wait} and retry as they already do. Best effort: after 2s or if Connect goes down, it logs TenantMigrationsNotReady and publishes anyway.

migrations-gate

  • One wait per tenant, on the node that runs Subscriptions.create, instead of one per channel. Channels never block.
  • During a rolling deploy, tenants whose Connect is on an old node wait the full timeout.

Comment thread config/test.exs Resolved
@leandrocp
leandrocp force-pushed the feat/wait-migrations-before-pg-changes branch from 9d222c7 to e2aad2c Compare October 29, 2026 14:18
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

CRAP Score Report

Summary: files=259 functions=1474 scored=1474 worst_score=15944.76

** (Mix) CRAP threshold failed: max_score=30.00
High scores: 30
  lib/extensions/postgres_cdc_rls/subscription_manager.ex Extensions.PostgresCdcRls.SubscriptionManager.handle_info/2 score=38.29
  lib/realtime/adapters/postgres/oid_database.ex Realtime.Adapters.Postgres.OidDatabase.name_for_type_id/1 score=15944.76
  lib/realtime/application.ex Realtime.Application.setup_region_mapping/0 score=47.11
  lib/realtime/nodes.ex Realtime.Nodes.default_region_mapping/1 score=129.85
  lib/realtime/operations.ex Realtime.Operations.rebalance/0 score=42.00
  lib/realtime/operations.ex Realtime.Operations.kill_connections_to_tenant_id/2 score=90.00
  lib/realtime/tenants/connect.ex Realtime.Tenants.Connect.handle_info/2 score=38.76
  lib/realtime_web/channels/auth/jwt_verification.ex RealtimeWeb.JwtVerification.generate_signer/3 score=30.78
  lib/realtime_web/channels/realtime_channel.ex RealtimeWeb.RealtimeChannel.handle_info/2 score=51.06
  lib/realtime_web/dashboard/feature_flags.ex RealtimeWeb.Dashboard.FeatureFlags.handle_event/3 score=112.70
  lib/realtime_web/dashboard/node_info.ex RealtimeWeb.Dashboard.NodeInfo.fetch_node_data/2 score=42.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.handle_event/3 score=552.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.handle_info/2 score=210.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.render_value/2 score=42.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.load_module_functions/1 score=42.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.parse_and_start/2 score=110.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.format_value/1 score=552.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.sort_entries/2 score=42.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.handle_event/3 score=72.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.execute_read_only/1 score=72.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.mask_sensitive_columns/1 score=42.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.compare_cells/2 score=42.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.format_cell/1 score=72.00
  lib/realtime_web/dashboard/tenant_migrations.ex RealtimeWeb.Dashboard.TenantMigrations.handle_info/2 score=156.00
  lib/realtime_web/live/components.ex RealtimeWeb.Components.input/1 score=90.00
  lib/realtime_web/live/inspector_live/conn_component.ex RealtimeWeb.InspectorLive.ConnComponent.handle_event/3 score=53.83
  lib/realtime_web/live/inspector_live/event_log_component.ex RealtimeWeb.InspectorLive.EventLogComponent.category_variant/1 score=35.00
  lib/realtime_web/live/inspector_live/event_log_component.ex RealtimeWeb.InspectorLive.EventLogComponent.event_label/1 score=51.43
  lib/realtime_web/live/inspector_live/index.ex RealtimeWeb.InspectorLive.Index.handle_event/3 score=30.84
  lib/realtime_web/live/status_live/index.ex RealtimeWeb.StatusLive.Index.handle_event/3 score=42.00

@coveralls

coveralls commented Oct 29, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 93.057% (+0.08%) from 92.98% — feat/wait-migrations-before-pg-changes into main

Comment thread lib/realtime/tenants/connect.ex Resolved
Comment thread lib/realtime/tenants/connect.ex Resolved
Comment thread lib/realtime/tenants/connect.ex Resolved
Comment thread lib/realtime/tenants/connect.ex Resolved
Comment thread lib/realtime/tenants/connect.ex Resolved
@leandrocp

Copy link
Copy Markdown
Member Author

@edgurgel thanks for the review, I simplified the whole thing based on your feedback.

@leandrocp
leandrocp requested a review from edgurgel November 2, 2026 17:11

@edgurgel edgurgel left a comment

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.

Added a few comments but other than those LGTM

@leandrocp
leandrocp force-pushed the feat/wait-migrations-before-pg-changes branch from cbc7084 to 7758556 Compare November 3, 2026 15:33
@blacksmith-sh

This comment has been minimized.

@leandrocp
leandrocp force-pushed the feat/wait-migrations-before-pg-changes branch 2 times, most recently from d69a5f5 to 2a34ba5 Compare November 3, 2026 17:55

@edgurgel edgurgel left a comment

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.

LGTM

@leandrocp
leandrocp force-pushed the feat/wait-migrations-before-pg-changes branch from 2a34ba5 to 46b9cae Compare November 4, 2026 14:50
@leandrocp
leandrocp merged commit 67af9ce into main Nov 4, 2026
56 checks passed
@leandrocp
leandrocp deleted the feat/wait-migrations-before-pg-changes branch November 4, 2026 15:08
@realtime-release-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.153.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants