Cannot run migrations on in-memory db
Closed this issue · 2 comments
LostKobrakai commented
I'm not really sure this is an issue with this library, but not using an in memory db works just fine.
Run using elixir script.exs
Mix.install([:ecto_sql, :ecto_sqlite3])
Application.put_env(:my_app, Repo, database: ":memory:", migration_lock: false)
defmodule Repo do
use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.SQLite3
end
:ok = Ecto.Adapters.SQLite3.storage_up(Repo.config())
Repo.start_link()
defmodule Migration do
use Ecto.Migration
def change do
create table("abc", primary_key: false) do
add(:id, :binary_id, null: false)
add(:uuid, :binary_id, null: false)
timestamps()
end
create table(:testing) do
add :company, :string
add :name, :string
add :vintage, :string
add :drunk_at, :utc_datetime
timestamps()
end
create index(:testing, [:company])
end
end
Ecto.Migrator.up(Repo, 0, Migration, log: :info, skip_table_creation: false)
** (Exqlite.Error) no such table: schema_migrations
SELECT CAST(s0."version" AS INTEGER) FROM "schema_migrations" AS s0
(ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:847: Ecto.Adapters.SQL.execute/6
(ecto 3.8.4) lib/ecto/repo/queryable.ex:221: Ecto.Repo.Queryable.execute/4
(ecto 3.8.4) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
(ecto_sql 3.8.3) lib/ecto/migrator.ex:536: Ecto.Migrator.lock_for_migrations/4
LostKobrakai commented
And due to good old rubber-ducking I found the issue. Need to set pool_size
to 1
with an in memory db.
warmwaffles commented
@LostKobrakai the in memory database is finicky with DBConnection
. If the pool count goes to zero, the database will be lost. I wish there was a better way to go beyond 1, but we can't without some changes upstream.