3

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.

Community
  • 1
  • 1
sashaegorov
  • 1,821
  • 20
  • 26

1 Answers1

10

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
Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • I've added `{:ecto, git: "git://github.com/elixir-ecto/ecto.git", override: true}` into my `mix.exs`, after I have updated dependencies, and it works. `mix ecto.migrate --log-sql` now shows desirable debug statements. I think your answer will remain valid after that feature is released. Thanks. – sashaegorov May 02 '17 at 14:30