Skip to content

Commit d6eb368

Browse files
committed
chore: try to always get the database created during tests
1 parent 51e4c10 commit d6eb368

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/support/containers.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,28 @@ defmodule Containers do
110110
end
111111
end
112112

113+
defp storage_up!(tenant) do
114+
settings =
115+
Database.from_tenant(tenant, "realtime_test", :stop)
116+
|> Map.from_struct()
117+
|> Keyword.new()
118+
119+
case Ecto.Adapters.Postgres.storage_up(settings) do
120+
:ok -> :ok
121+
{:error, :already_up} -> :ok
122+
_ -> raise "Failed to create database"
123+
end
124+
end
125+
113126
# Might be worth changing this to {:ok, tenant}
114127
def checkout_tenant(opts \\ []) do
115128
with container when is_pid(container) <- :poolboy.checkout(Containers.Pool, true, 5_000),
116129
port <- Container.port(container) do
117130
tenant = Generators.tenant_fixture(%{port: port, migrations_ran: 0})
118131
run_migrations? = Keyword.get(opts, :run_migrations, false)
119132

133+
storage_up!(tenant)
134+
120135
settings = Database.from_tenant(tenant, "realtime_test", :stop)
121136
settings = %{settings | max_restarts: 0, ssl: false}
122137
{:ok, conn} = Database.connect_db(settings)

0 commit comments

Comments
 (0)