From 5f44c1a54b06b4e851d695478a284440c9900309 Mon Sep 17 00:00:00 2001 From: Ilia Borovitinov Date: Wed, 20 Sep 2023 12:18:24 +0300 Subject: [PATCH] feat: suffix slot name with db name (#450) 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. --- .changeset/gold-knives-dress.md | 5 +++++ .../electric/lib/electric/plug/satellite_websocket_plug.ex | 2 +- components/electric/lib/electric/replication/connectors.ex | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/gold-knives-dress.md diff --git a/.changeset/gold-knives-dress.md b/.changeset/gold-knives-dress.md new file mode 100644 index 0000000000..bf406732e2 --- /dev/null +++ b/.changeset/gold-knives-dress.md @@ -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 diff --git a/components/electric/lib/electric/plug/satellite_websocket_plug.ex b/components/electric/lib/electric/plug/satellite_websocket_plug.ex index 70be000f58..482857cf43 100644 --- a/components/electric/lib/electric/plug/satellite_websocket_plug.ex +++ b/components/electric/lib/electric/plug/satellite_websocket_plug.ex @@ -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), diff --git a/components/electric/lib/electric/replication/connectors.ex b/components/electric/lib/electric/replication/connectors.ex index 0156c44aa3..0c36f1d199 100644 --- a/components/electric/lib/electric/replication/connectors.ex +++ b/components/electric/lib/electric/replication/connectors.ex @@ -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