When I update from controller I use changeset model method and for example: log changes (changeset.changes).
Is it possible to catch update (default values) with mix ecto.migrate command?
defmodule MyProject.Repo.Migrations.AddIsVisibleToPost do
use Ecto.Migration
def change do
alter table(:posts) do
add :is_visible, :boolean, default: true # Post change here
#Ecto.Changeset<action: nil, changes: %{is_visible: true}, errors: [],
data: #MyProject.Post<>, valid?: true>
end
end
end
Or I need to fetch all table entries and log changes in loop?
@Eiji could you show how you do it.
Could you also give the use cases of using this.
I would like to apply the same logic like when alter tables I would like to logged changes to the database while I am developing and testing.
Just fetch all entries from database by Ecto query methods and pass result to Enum.each.
I want to log all database changes including migrations. Then user with special role could revert all changes in database without rollback migrations. I don’t finish this project, so I can’t show my code yet.