-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Introduce AllCops: MigratedSchemaVersion
config
#1383
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, much nicer than having to configure it for each cop individually. This makes sense I think, you never want any of these cop to run for already run migrations and potentially change them. cc @fatkodima
Hm, would it be possible to add a hint for
Or something like that. |
This PR introduces `AllCops: MigratedSchemaVersion` config. By specifying the `MigratedSchemaVersion` option, migration files that have already been run can be ignored. When `MigratedSchemaVersion: '20241225000000'` is set, migration files lower than or equal to '20241225000000' will be ignored. For example, to ignore db/migrate/20241225000000_create_articles.rb and earlier migrations you would configure it the following way: ```yaml AllCops MigratedSchemaVersion: '20241225000000' ``` This prevents inspecting schema settings for already applied migration files. Changing already applied migrations should be avoided because it can lead to the schema getting out of sync between your local copy and what it actually is in production, depending on when `bin/rails db:migrate` was executed. If you want to modify your schema to comply with the cops, you should instead create new migrations.
b2bbf6f
to
86b7a55
Compare
As long as it doesn't result in redundant message display, it might be possible to add some sort of hint. In any case, this could be handled as a separate enhancement. |
NOTE: The build error in the JRuby CI matrix can be ignored as it has been reported in ruby/bigdecimal#309. |
I just added this to my config and thought it wasn't working. I expected all cops to ignore old migrations. But I still saw lots of violations. Now looking at the code changes here, I think that only migration-related cops ignore old migrations. If that's the case then it's confusing to configure Can you clarify this? |
This PR introduces
AllCops: MigratedSchemaVersion
config.By specifying
MigratedSchemaVersion
option, migration files that have been migrated can be ignored. WhenMigratedSchemaVersion: '20241231000000'
is set. Migration files lower than or equal to '20250101000000' will be ignored. For example, this is the timestamp in db/migrate/20250101000000_create_articles.rb.This prevents inspecting schema settings for already applied migration files and avoids having different database schemas depending on when
bin/rails db:migrate
is executed.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.