I encountered problems similar to Can't drop postgres db when in test env
where I cannot drop my database during test. As like other post, my config is using sandbox:
config :myapp, MyApp.Repo,
url: "postgres://postgres:postgres@localhost/myapp_test",
pool: Ecto.Adapters.SQL.Sandbox
and I use setup
in my tests:
setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(MyApp.Repo)
end
test "something" do
Mix.Task.rerun("ecto.drop")
Mix.Task.rerun("ecto.create")
Mix.Task.rerun("ecto.migrate")
# ...
end
Other tests work fine with this sandbox (insert, update, delete, etc), but I get errors when I try to drop/create:
** (Mix.Error) The database for MyApp.Repo couldn't be dropped: ERROR 55006 (object_in_use) database "tobby_test" is being accessed by other users
There are 10 other sessions using the database.
I did reboot and there are no psql or GUI clients or iex connections. I think my app is connecting to the database somewhere but I do not understand how. Is there a better way to drop and recreate database?