Currently, I'm looking for the way to add SQL-statements logging while running mix
tasks. For example, commands such mix ecto.rollback
and mix ecto.migrate
outputs informative:
...
13:45:53.016 [info] == Running Repo.Migrations.AddAmountToUserResources.change/0 backward
13:45:53.016 [info] alter table user_resources
...
However instead of mysterious alter table user_resources
I'd like to see exact SQL-statements generated by ecto
which hits DB.
Is there any way to do that?
I've checked a couple of SO answers, which looks relevant (e.g. Disable Elixir Ecto Debug output). Unfortunately, they didn't help me in my case above. Thanks in advance.
A feature to allow logging raw SQL was added to Ecto on 15 Jan 2017. There hasn't been a release of Ecto since then. Once there is, or you switch to using the version of Ecto from Github master branch, you can pass --log-sql
to the commands ecto.migrate
and ecto.rollback
to make it log the complete query that's executed.
$ mix ecto.migrate --log-sql
$ mix ecto.rollback --log-sql