Skip to content

Commit

Permalink
fix: Revert maybe run migrations (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco authored Nov 12, 2024
1 parent f0eb097 commit c8d0b60
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
11 changes: 8 additions & 3 deletions lib/realtime/tenants/connect/migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ defmodule Realtime.Tenants.Connect.Migrations do
alias Realtime.Tenants.Migrations

@impl true
def run(%{db_conn_pid: db_conn_pid, tenant: tenant} = acc) do
{:ok, _} = Migrations.maybe_run_migrations(db_conn_pid, tenant)
{:ok, acc}
def run(%{tenant: tenant} = acc) do
[%{settings: settings} | _] = tenant.extensions
migrations = %Migrations{tenant_external_id: tenant.external_id, settings: settings}

case Migrations.run_migrations(migrations) do
:ok -> {:ok, acc}
{:error, error} -> {:error, error}
end
end
end
2 changes: 1 addition & 1 deletion lib/realtime_web/channels/realtime_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ defmodule RealtimeWeb.RealtimeChannel do

@spec only_private?(String.t(), map()) :: :ok | {:error, :private_only}
defp only_private?(tenant_id, %{assigns: %{check_authorization?: check_authorization?}}) do
tenant = Tenants.get_tenant_by_external_id(tenant_id)
tenant = Tenants.Cache.get_tenant_by_external_id(tenant_id)

cond do
tenant.private_only and !check_authorization? -> {:error, :private_only}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.33.40",
version: "2.33.41",
elixir: "~> 1.16.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
5 changes: 2 additions & 3 deletions test/realtime/tenants/connect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,11 @@ defmodule Realtime.Tenants.ConnectTest do
end

test "on migrations failure, stop the process", %{tenant: tenant} do
with_mock Realtime.Tenants.Migrations, [],
maybe_run_migrations: fn _, _ -> raise("error") end do
with_mock Realtime.Tenants.Migrations, [], run_migrations: fn _ -> raise("error") end do
assert {:error, :tenant_database_unavailable} =
Connect.lookup_or_start_connection(tenant.external_id)

assert_called(Realtime.Tenants.Migrations.maybe_run_migrations(:_, :_))
assert_called(Realtime.Tenants.Migrations.run_migrations(:_))
end
end

Expand Down

0 comments on commit c8d0b60

Please sign in to comment.