Closed stevegeek closed 1 month ago
Imagine a model with validates :name, uniqueness: {case_sensitive: false} (with PG this will use lower(name)).
validates :name, uniqueness: {case_sensitive: false}
lower(name)
This will make database_consistency report:
MissingUniqueIndexChecker fail MyModel lower(name) model should have proper unique index in the database
Generating a migration 'autocorrect' creates:
def change add_index :my_models, %w[lower(name)], name: :index_my_models_lower_name_, unique: true end
Running this migration gives:
PG::UndefinedColumn: ERROR: column "lower(name)" does not exist ..._add_my_models_lower_name__index.rb:3:in 'change'
The correct migration is:
add_index :my_models, "lower(name)", name: :index_my_models_lower_name_, unique: true
database_consistency version: 1.7.23 Rails 7.1
Thanks for all your work on this gem!
Hi @stevegeek,
Thank you for noticing this! It should be fixed in 1.7.24. Please try it out and let me know if it isn't working.
https://github.com/djezzzl/database_consistency/pull/230
@djezzzl thank you!
Imagine a model with
validates :name, uniqueness: {case_sensitive: false}
(with PG this will uselower(name)
).This will make database_consistency report:
MissingUniqueIndexChecker fail MyModel lower(name) model should have proper unique index in the database
Generating a migration 'autocorrect' creates:
Running this migration gives:
PG::UndefinedColumn: ERROR: column "lower(name)" does not exist ..._add_my_models_lower_name__index.rb:3:in 'change'
The correct migration is:
add_index :my_models, "lower(name)", name: :index_my_models_lower_name_, unique: true
database_consistency version: 1.7.23 Rails 7.1
Thanks for all your work on this gem!