dmitriid
Hi all
I’ve been trying a gung-ho approach to updating ecto_sqlite2 to support ecto3, and on the surface it seems to be straightforward enough: implement the new callbacks, make sure functions return updated responses etc. And now I’m stuck in an issue when running ecto tests:
when running ecto’s Migrator.up , the code seemingly runs all the statement until it tries to insert data into one of the tables. Sqlite returns busy , and then the migration fails with
{"busy",0}
{"busy",1}
{"busy",2}
{"busy",3}
{"busy",4}
{"busy",5}
Sqelect.DbConnection.Protocol (#PID<0.278.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.319.0> exited
** (Sqelect.DbConnection.Error) {{:bad_return_value, :too_many_tries}, {GenServer, :call, [#PID<0.315.0>, {:query_rows, "INSERT INTO \"schema_migrations\" (\"version\",\"inserted_at\") VALUES (?1,?2)", [timeout: :infinity, decode: :manual, types: true, bind: [0, "2020-07-28T13:25:33"]]}, :infinity]}}
(ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:593: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto 3.4.5) lib/ecto/repo/schema.ex:661: Ecto.Repo.Schema.apply/4
(ecto 3.4.5) lib/ecto/repo/schema.ex:263: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
(ecto_sql 3.4.5) lib/ecto/migrator.ex:641: Ecto.Migrator.verbose_schema_migration/3
(ecto_sql 3.4.5) lib/ecto/migrator.ex:293: Ecto.Migrator.async_migrate_maybe_in_transaction/6
(ecto_sql 3.4.5) lib/ecto/migrator.ex:211: anonymous fn/5 in Ecto.Migrator.up/4
(ecto_sql 3.4.5) lib/ecto/migrator.ex:493: Ecto.Migrator.lock_for_migrations/4
integration/sqelect/test_helper.exs:93: (file)
The problem is: I don’t have enough knowledge of either Ecto or Elixir to properly debug this issue. If anyone has some spare time to look at this, it would be greatly appreciated.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Not sure you can get any guarantees since the library is only guaranteed to work with Ecto 2.
But, in this case maybe you just haven’t opened it with the right mode (should be serial).
dmitriid
That’s why I’m attempting to port it to Ecto 3
Thank you, I’ll look into that! (even though the underlying esqlite doesn’t let you provide modes)
idi527
AFAIK Ecto 3 locks tables and uses two connections to the db during migrations. Maybe you can use some combination of
:migration_lockoption and the number of connectionspool_size: 1to work around your problem.I couldn’t make your example work since it’s missing a dependency:
dimitarvp
Well, I am authoring an sqlite3 Elixir library (which is a bridge to an excellent Rust library) but life hasn’t been kind this year and I am just beginning to recover and might resume work on the first stable release Soon™.
dmitriid
Ah! Thank you for the tip on the migration_lock_option! I’ll definitely look into that.
Replace
{:sqlitex, "~>1.7.1", path: "deps/sqlitex"}with{:sqlitex, "~>1.7.1"}inmix.exs. I usepathto sprinkle dependencies’ code withIO.inspectdmitriid
Just tried
migration_lock: nil, pool_size: 1and got a different error:Well, it’s progress
So I can look into the underlying cause more closely
dmitriid
I should’ve
inspected moreBasically, the tests end up opening multiple connections anyway. For
TestRepo:For a total of 11 connections. And in my code I end up starting 11 sqlite gen servers which … is not ideal
Lankester
Hello
I am rather fond of Sqlite and thought it would be fun to update
sqlite_ecto2so it works with Ecto 3.I have hit the same
{"busy",0..5}issue as @dmitriid.This appears to be due to the Ecto migrator running the migration in a transaction via an async task, but before the transaction commits the parent task tries to insert into the
schema_migrationstable. I believe this is the cause of the busy responses because the SQLite database is locked at the beginning of the transaction which prevents the insert to theschema_migrationstable from the parent connection.This home-baked debug output from running the tests shows the PIDs associated with the relevant queries and you can see
#PID<0.425.0>starts a transaction but then the parent#PID<0.426.0>tries an insert before the original transaction commits.This seems to be related to the following function in
ecto_sql:https://github.com/elixir-ecto/ecto_sql/blob/b35dd7c08f76396d7289bd6cd490974e99983749/lib/ecto/migrator.ex#L290-L312
Can anybody point me in the right direction so I can solve this in the adapter? I had a play with implementing
lock_for_migrations/3but don’t think this is relevant as there isn’t, to my knowledge, an SQLite command that would modify the behaviour I’m seeing.I can get around the error by setting
supports_ddl_transaction?to false in the adapter, but that doesn’t feel right as Sqlite3 does support DDL in transactions.lud
Hi @Lankester and @dimitarvp , have you made some progress on your implementations of Sqlite3 / Ecto3 ?
I would be glad to help. PM me
dimitarvp
Ah, I’ve got nothing to hide.
Recently started a new job and it’s taking most of my time – initial good impressions, you know.
Also due to the closure of the gyms I got hit by very low energy levels and I am not motivated to work on anything beyond the main job.
Happily though both things will come to an end soon (not the job itself, just the initial flurry of tasks in it) and I expect to resume work on
xqlite. Going to spend an hour on the treadmill in the gym at Monday or I’ll change my name!Last status was that I completely reworked the Rust code and it’s at least 5x faster now, plus much cleaner. And for my library the Rust code is honestly 90% of the work.
What can you do to help? Well, once I have the Rust code in place (which I do, but have to do a few final iterations on it, add some more unit tests and optionally benchmarks) and push it in the GitHub repo, you can contribute test scenarios and the tests themselves. Also I’d appreciate a second pair of eyes on the Elixir API design. Promise to keep you in the loop since you expressed interest. Expect actual updates in the next 2-4 weeks.