Is there a simple way to transform Ecto migrations to sql script?

Scenario: I have an elixir app and postgresql database in a protected Azure environment. Protected meaning you can’t talk to the network its on from your dev box or any public box. Is there an adaptor or lib that will take ecto migrations and turn them into one .sql file that can then be moved over to the postgres vm and executed?

1 Like

No, as you can’t know which migrations to run, without asking the database which migrations have already been run.

Also migrations can contain arbitrary logic, that can’t get compiled into SQL.

But, no connection between your device machine and the application has to be made, just check during app boot if migrations are necessary.

IIRC in the destillery documentary was an example that did something similar.

Sorry for the old topic but I did not feel creating the same one, only more recent.

I need to run migrations with liquibase (I do not have a choice on that). It there a way to generate the sql scripts somehow ? Basically logging the queries sent to posgres to a file would be fine.

For the “which” migration to run, I can just create a script to run them one by one and generate the scrips. They are not doing inserts, just changing the schema.

Any idea?


Easy way… $ ecto.migrate --log-migrations-sql but you have to copy the output yourself. This works if you have a local database which has the same schema and you do not have Elixir/SQL code doing any one-by-one migration.

Thanks !

Maybe it is possible to use a custom logger backend to generate the files.