Skip to content

Commit ac1ea41

Browse files
committed
fix(deploy): use with_repo for schema drop to avoid pool disconnect
DROP SCHEMA CASCADE kills all active pool connections. Use Ecto.Migrator.with_repo to get a managed connection for the drop/recreate/migrate sequence, then start the full app only for seeding.
1 parent 281484b commit ac1ea41

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

lib/craftplan/release.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ defmodule Craftplan.Release do
1818
end
1919

2020
def reset do
21-
start_app_without_server()
21+
load_app()
2222

23+
# Use a temporary connection to drop/recreate the schema, avoiding
24+
# pool connection issues from DROP SCHEMA CASCADE.
2325
for repo <- repos() do
24-
repo.query!("DROP SCHEMA public CASCADE")
25-
repo.query!("CREATE SCHEMA public")
26+
{:ok, _, _} =
27+
Ecto.Migrator.with_repo(repo, fn repo ->
28+
repo.query!("DROP SCHEMA public CASCADE")
29+
repo.query!("CREATE SCHEMA public")
30+
Ecto.Migrator.run(repo, :up, all: true)
31+
end)
2632
end
2733

28-
Ecto.Migrator.with_repo(Craftplan.Repo, &Ecto.Migrator.run(&1, :up, all: true))
2934
seed()
3035
end
3136

0 commit comments

Comments
 (0)