Skip to content

Commit

Permalink
feat: suffix slot name with db name (#450)
Browse files Browse the repository at this point in the history
This change allows running electric per db, since slots have to be
instance-unique, not database-unique. This is not related to
horizontally scaling Electrics against a single PG instance.
  • Loading branch information
icehaunter authored Sep 20, 2023
1 parent fbf050f commit 5f44c1a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-knives-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@core/electric": patch
---

Suffix electric-created slot with db name to be able to run Electric per database on a single PostgreSQL instance
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Electric.Plug.SatelliteWebsocketPlug do
&Electric.Replication.InitialSync.query_subscription_data/2
end)

@currently_supported_versions ">= 0.6.0 and <= #{Electric.vsn()}"
@currently_supported_versions ">= 0.6.0 and <= #{%{Electric.vsn() | pre: []}}"

def call(conn, handler_opts) do
with {:ok, conn} <- check_if_valid_upgrade(conn),
Expand Down
3 changes: 2 additions & 1 deletion components/electric/lib/electric/replication/connectors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ defmodule Electric.Replication.Connectors do
@spec get_replication_opts(config()) :: replication_opts()
def get_replication_opts(config) do
origin = origin(config)
database_name = get_in(config, [:connection, :database]) || "test"

config
|> Keyword.fetch!(:replication)
|> Map.new()
|> Map.put(:slot, Extension.slot_name())
|> Map.put(:slot, Extension.slot_name() <> "_#{database_name}")
|> Map.put(:publication, Extension.publication_name())
|> Map.put(:subscription, to_string(origin))
end
Expand Down

0 comments on commit 5f44c1a

Please sign in to comment.