ctran / annotate_models

Annotate Rails classes with schema and routes info
Other
4.43k stars 622 forks source link

annotate_models doesn't auto-annotate on down / rollback migrations in multi-DB environments #995

Open weyus opened 1 year ago

weyus commented 1 year ago

When I run a forward migration, my models are annotated correctly.

Because I'm running two DBs locally, I have to specify a DB name for either db:down or db:rollback. For db:down it appears that annotations run but comment doesn't change in model. For db:rollback it appears that annotations don't run, and of course, comment doesn't change in model.

I'm guessing that the issue is that both db:rollback and db:down require specific DB names and something is getting confused.

Commands

Command:

rails db:migrate:down:development VERSION=20230912185858

Output:

== 20230912185858 AddSomeColumnToAppointments: reverting ======================
-- remove_column(:appointments, :some_column, :string)
   -> 0.0011s
== 20230912185858 AddSomeColumnToAppointments: reverted (0.0030s) =============

Dumping schema
Model files unchanged.

Looks like annotate runs, says no model change. NO change to model comment.

Command:

rails db:rollback:development VERSION=20230912185858

Output:

== 20230912185858 AddSomeColumnToAppointments: reverting ======================
-- remove_column(:appointments, :some_column, :string)
   -> 0.0044s
== 20230912185858 AddSomeColumnToAppointments: reverted (0.0064s) =============

Dumping schema

Looks like annotate doesn't run. NO change to model comment.

NOTE: If I re-run annotate on command line after reversion, model comments are fixed.

Version

=============

I'm attempting to fix by doing the following in a file lib/tasks/db/enhancements.rake, but it's not invoking the annotate_models task.

Rake::Task["db:rollback"].enhance do
  Rake::Task["annotate_models"].execute
end

Rake::Task["db:migrate:down"].enhance do
  Rake::Task["annotate_models"].execute
end