adrian
I’m using distillery release hooks for running ecto migrations when the app starts. I’ve followed the distillery guide but is not working. The scrips are not being copied to the device.
This is the related config in the rel/config.exs file:
set commands: [
migrate: "rel/commands/migrate.sh",
seed: "rel/commands/seed.sh",
]
set pre_start_hooks: "rel/hooks/pre_start"
And under rel/hooks/pre_start I have the same migrate.sh file as in rel/commands/migrate.sh:
#!/bin/sh
# exit if any subcommand or pipeline returns a non-zero status.
set +e
echo "Starting migrations!"
release_ctl eval --mfa "Ui.ReleaseTasks.migrate/1" --argv -- "$@"
command
echo "Ending migrations!"
Thanks.
Adrián
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
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
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ConnorRigby
Nerves strips out any runtime components of Distillery. Check this post i wrote a while back to run Ecto migrations on Nerves devices.
mobileoverlord
Nerves does not support using distillery release hooks. This is because Nerves uses a program called erlinit to boot erlang as early and as safely as possible. Writing embedded systems using Nerves means that your application code will live mostly in Elixir / Erlang. This means that its really important that the VM comes up and stays running to prevent bricking the device. To make the boot process more reliable we created shoehorn, an OTP app that is included in Nerves projects by default.
Shoehorn provides two major advantages.
The second point is the one where you can perform actions similar to that of Distillery release hooks. Using Blinky as an example, we can see how the initial config.exs file is generated:
The option
:inittakes a list of OTP applications, and MFA’s to execute before the main application start. This is an ordered list. the default[:nerves_runtime, :nerves_init_gadget]means that:nerves_runtimeand its deps will start first, followed by:nerves_init_gadgetand its deps, followed by the main app declared in the key:app. You could add other OTP application names to this list or MFA’s such asinit: [{IO, :puts, ["init_1"]}]. Shoehorn has an example app that performs MFA’s on init hereadrian
Thanks a lot for your detailed answer @mobileoverlord!
What I’m trying to do is to run migrations for the Phoenix UI. I’ve added the migration release task to shoehorn but I get this error:
I guess this is because the Ui app has not started yet.
I start the apps before running the migrations, this is the script based on the distillery recommendations:
I think it fails because the Ui app has not started yet.
I’m not 100% sure about this, but I think the Ui is started with the app because it’s a dependency, but could I move the Ui start to soehorn instead of being done automatically? After that I could put the migrations script and remove the
start_servicesandstop_servicesfunctions.Does it make sense? Could it fail because starting up the db takes time and the migrations will run immediately?
@ConnorRigby the code I use is pretty similar to yours. Start the apps, migrate and stop.
I added to the Ui
application.exbut it doesn’t work either. The migrations work but after that, the Ui won’t start:
The repos were already started, I tried to stop them but somehow I still get this message.
ConnorRigby
So the reason that the
shoehornmethod won’t work seems to be because of a configuration error. I can’t say i’ve ever used this method so i’ll let Justin chime in on that.I still use ecto 2 so it’s possible something changed in the migration code, but in my application after running migrations, the repo is stopped. Which adapter are you using?
adrian
I used your code in the past and worked fine, I moved to PostgreSQL (the current adapter) and still worked fine. This was some months ago. After this I worked only in the UI, and in the way I upgraded versions. Everything worked for Phoenix, but last week when I tested the Ui in nerves, I got some issues. This is the one that is blocking the device to work.
ConnorRigby
are you using Ecto2 or Ecto3? as a quick hack you could essentially stop all Ecto/Repo processes before exiting the
Ui.ReleaseTasks.migrate()codeadrian
I already did that with:
And didn’t work.
I’m getting some results now.
I tried to start the ui and after that run the migrations adding at the end of shoehorn:
I removed the
start_servicesandstop_servicesbecause the ui was supposed to start it, but migrations didn’t run.Until I found out that I had a genserver for an AMQP service with RabbitMQ that had the wrong credentials, so it didn’t connect to RabbitMQ and the Ui was never fully started so migrations never run.
I just commented that genserver and migrations seems to run, but I’m just testing yet.
If I make this system work again in the RPI3, with custom buildroot with PostgreSQL, a nice Ui with Elm and websockets, realtime events using RabbitMQ, I’ll be very very excited
adrian
btw @ConnorRigby I forgot to mention I’m using Ecto3
adrian
It works!
After fixing the issue with the AMQP genserver adding this to shoehorn worked: