Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weyus opened this issue Sep 12, 2023 · 0 comments

Comments

@weyus
Copy link

weyus commented Sep 12, 2023

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

  • annotate version: 3.2.0
  • rails version: 6.1.7.6
  • ruby version: 3.2.2

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant