elixir-sqlite / ecto_sqlite3

An Ecto SQLite3 adapter.
https://hexdocs.pm/ecto_sqlite3
MIT License
300 stars 45 forks source link

Support DDL transactions #123

Closed greg-rychlewski closed 1 year ago

greg-rychlewski commented 1 year ago

Closes part of https://github.com/elixir-sqlite/ecto_sqlite3/issues/87.

It doesn't seem to me like anything special needs to be done to support DDL transactions for SQLite. The tests were copied from Ecto SQL and seem to pass with no issue.

For the other part of the issue, locking to prevent concurrent migrations, I don't think anything can be done as is. Ecto requires a separate transaction to hold the lock, independent of the transaction used to perform the migration. This is to allow users the ability to lock even if their migration command cannot be run inside of a transaction.

From what I can tell this is not compatible with how locks work in SQLite. It seems the same transaction has to hold the lock and do the writing. There's no mutually exclusive lock that can be held that will allow a subsequent transaction to perform a DDL statement, from what I can see.

I don't think it's completely hopeless. But I just have to figure out a good proposal for Ecto for an option to allow everything to be in one transaction.

greg-rychlewski commented 1 year ago

I was thinking of a proposal to ecto sql to help with the locks for concurrent migrations. If I could get something like this accepted do you think you'd want to use it for this adapter?

Create a new configuration option called separate_lock_transaction/separate_migration_transaction

warmwaffles commented 1 year ago

That should work provided they have the database's journal opened with the wal set.