Mix ecto tasks, check if database or table has been created before running mix tasks

Hi, I’m wondering if there are any ecto mix tasks for two things:

  1. Check if a database has been created before running mix ecto.create in a docker container

  2. Check if a table has been created before running mix ecto.migrate in a docker container.

If not, can someone please tell me how to run this as an entrypoint shell script?

A common way to do it was simply doing ENTRYPOINT ["mix", "do", "ecto.create,", "ecto.migrate,", "phx.server"] (replace the last one with the actual task that starts your application.

1 Like

This will run ecto.create and ecto.migrate every single time I do a docker-compose up, which in turn does a compile for each of these commands, how do I reduce the number of compiles. I do not want to compile 3 times every time I do docker-compose up

It shouldn’t.

Perhaps you should show us a bit more info about how you build and start your containers? compose file included.

4 Likes