diff --git a/config/runtime.exs b/config/runtime.exs index b0cf57690..73cbd88b9 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -1,5 +1,7 @@ import Config +version = Mix.Project.config()[:version] |> String.replace(".", "_") |> String.downcase() + config :logflare_logger_backend, url: System.get_env("LOGFLARE_LOGGER_BACKEND_URL", "https://api.logflare.app") @@ -9,6 +11,9 @@ username = System.get_env("DB_USER", "postgres") password = System.get_env("DB_PASSWORD", "postgres") database = System.get_env("DB_NAME", "postgres") port = System.get_env("DB_PORT", "5432") +slot_name_suffix = System.get_env("SLOT_NAME_SUFFIX", version) + +config :realtime, slot_name_suffix: slot_name_suffix if config_env() == :prod do secret_key_base = diff --git a/lib/extensions/postgres_cdc_rls/replication_poller.ex b/lib/extensions/postgres_cdc_rls/replication_poller.ex index 093dcf8eb..ab1721da8 100644 --- a/lib/extensions/postgres_cdc_rls/replication_poller.ex +++ b/lib/extensions/postgres_cdc_rls/replication_poller.ex @@ -151,14 +151,8 @@ defmodule Extensions.PostgresCdcRls.ReplicationPoller do end def slot_name_suffix() do - case System.get_env("SLOT_NAME_SUFFIX") do - nil -> - "" - - value -> - Logger.debug("Using slot name suffix: " <> value) - "_" <> value - end + slot_name_suffix = Application.get_env(:realtime, :slot_name_suffix) + "_" <> slot_name_suffix end defp convert_errors([_ | _] = errors), do: errors diff --git a/lib/extensions/postgres_cdc_rls/supervisor.ex b/lib/extensions/postgres_cdc_rls/supervisor.ex index 06f95bd90..65cc2de5a 100644 --- a/lib/extensions/postgres_cdc_rls/supervisor.ex +++ b/lib/extensions/postgres_cdc_rls/supervisor.ex @@ -15,7 +15,6 @@ defmodule Extensions.PostgresCdcRls.Supervisor do def init(_args) do load_migrations_modules() - :syn.set_event_handler(Realtime.SynHandler) :syn.add_node_to_scopes([PostgresCdcRls]) children = [ diff --git a/lib/realtime/application.ex b/lib/realtime/application.ex index 49c7b6dc7..afacecf1c 100644 --- a/lib/realtime/application.ex +++ b/lib/realtime/application.ex @@ -42,8 +42,10 @@ defmodule Realtime.Application do name: Realtime.Registry.Unique ) + :syn.set_event_handler(Realtime.SynHandler) :ok = :syn.add_node_to_scopes([Realtime.Tenants.Connect]) :ok = :syn.add_node_to_scopes([:users, RegionNodes]) + region = Application.get_env(:realtime, :region) :syn.join(RegionNodes, region, self(), node: node()) diff --git a/mix.exs b/mix.exs index 1733195d8..4857e1587 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do def project do [ app: :realtime, - version: "2.25.7", + version: "2.25.8", elixir: "~> 1.14.0", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, diff --git a/test/realtime/extensions/cdc_rls/replication_poller_test.exs b/test/realtime/extensions/cdc_rls/replication_poller_test.exs index 14dd27335..2669fe81d 100644 --- a/test/realtime/extensions/cdc_rls/replication_poller_test.exs +++ b/test/realtime/extensions/cdc_rls/replication_poller_test.exs @@ -287,14 +287,21 @@ defmodule ReplicationPollerTest do end describe "slot_name_suffix" do - test "when no SLOT_NAME_SUFFIX" do - System.delete_env("SLOT_NAME_SUFFIX") - assert Poller.slot_name_suffix() == "" + setup do + slot_name_suffix = Application.get_env(:realtime, :slot_name_suffix) + + on_exit(fn -> Application.put_env(:realtime, :slot_name_suffix, slot_name_suffix) end) + end + + test "uses Application.get_env/2 with key :slot_name_suffix" do + slot_name_suffix = Generators.rand_string() + Application.put_env(:realtime, :slot_name_suffix, slot_name_suffix) + assert Poller.slot_name_suffix() == "_" <> slot_name_suffix end - test "when SLOT_NAME_SUFFIX defined" do - System.put_env("SLOT_NAME_SUFFIX", "some_val") - assert Poller.slot_name_suffix() == "_some_val" + test "defaults to project version" do + version = Mix.Project.config()[:version] |> String.replace(".", "_") + assert Poller.slot_name_suffix() == "_" <> version end end end