Migration in sqlite3 on volume fails

I’m trying to get phoenix with sqlite3 working. I mounted a volume in which I placed a sqlite db. Everything works now except the migrations running. Im gussing it could be because they run in the builder and the builder doesn’t have access to the volume. If I comment out the migrations everything works but if I keep them it fails:

  21:23:21.352 [error] Exqlite.Connection (#PID<0.128.0>) failed to connect: ** (Exqlite.Error) got :enoent while retrieving Exception.message/1 for %Exqlite.Error{message: :enoent, statement: nil} (expected a string)
         21:23:21.352 [error] Exqlite.Connection (#PID<0.127.0>) failed to connect: ** (Exqlite.Error) got :enoent while retrieving Exception.message/1 for %Exqlite.Error{message: :enoent, statement: nil} (expected a string)
         21:23:22.769 [error] Exqlite.Connection (#PID<0.128.0>) failed to connect: ** (Exqlite.Error) got :enoent while retrieving Exception.message/1 for %Exqlite.Error{message: :enoent, statement: nil} (expected a string)
             indexes with a migration_lock)

Any idea how to fix it? Would be nice to just have the migrations run automatically and not having to download them to the local computer and then run them there and then upload the files to the volume again.

Are you using the standard migration stuff that was generated in a Release module in your app by phx.gen.release or do you have such a module already that is run on deploy?

1 Like

I have packaged my phoenix app as an release and I’m using the release_command option available in the fly.toml to execute them :slight_smile: works like a charm with SQLite3.

I’m pretty sure the volume is not available in the builder.

Edit: right, the sqlite app I got is running migrations on boot :man_facepalming:t3: that’s why it woks :sweat_smile:

1 Like

That’s correct! The release_command won’t work with sqlite. It runs in an entirely different container before it stops your existing vm. You’ll need to run migrations when the process boots to perform sqlite migrations.

2 Likes

Makes sense. Any hint on the best way to run migrations on boot? Like how to you manage that? From where would I call that?

You can run your release migration within your application.ex start, conditionally per env if you’d like.

3 Likes