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

RedundantIndexChecker autofix create incorrect migration #231

Closed
ducmanh2111 opened this issue Aug 23, 2024 · 1 comment
Closed

RedundantIndexChecker autofix create incorrect migration #231

ducmanh2111 opened this issue Aug 23, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ducmanh2111
Copy link

Due to the lack of table_name and column for RedundantIndexChecker, the migration generated from autofix writer was incorrect.

Given
Step 1: I ran bundle exec database_consistency and it received:
image
Step 2: I ran bundle exec database_consistency -f and it created a migration to fix the check:

class RemoveIndexInvoiceNotesOnInvoiceIdIndex < ActiveRecord::Migration[6.1]
  def change
    remove_index nil, name: 'index_invoice_notes_on_invoice_id'
  end
end

When
I ran bundle exec rails db:migrate

Then

== 20240823165209 RemoveIndexInvoiceNotesOnInvoiceIdIndex: migrating ==========
-- remove_index(nil, {:name=>"index_invoice_notes_on_invoice_id"})
rails aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Incorrect table name ''
/myapp/db/migrate/20240823165209_remove_index_invoice_notes_on_invoice_id_index.rb:3:in `change'
/myapp/bin/rails:5:in `<top (required)>'
/myapp/bin/spring:10:in `block in <top (required)>'
/myapp/bin/spring:7:in `<top (required)>'

Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect table name ''
/myapp/db/migrate/20240823165209_remove_index_invoice_notes_on_invoice_id_index.rb:3:in `change'
/myapp/bin/rails:5:in `<top (required)>'
/myapp/bin/spring:10:in `block in <top (required)>'
/myapp/bin/spring:7:in `<top (required)>'

Caused by:
Mysql2::Error: Incorrect table name ''
/myapp/db/migrate/20240823165209_remove_index_invoice_notes_on_invoice_id_index.rb:3:in `change'
/myapp/bin/rails:5:in `<top (required)>'
/myapp/bin/spring:10:in `block in <top (required)>'
/myapp/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Expected Output

class RemoveIndexInvoiceNotesOnInvoiceIdIndex < ActiveRecord::Migration[6.1]
  def change
    remove_index :invoice_notes, name: 'index_invoice_notes_on_invoice_id', column: :invoice_id
  end
end
@djezzzl djezzzl added the bug Something isn't working label Dec 26, 2024
@djezzzl
Copy link
Owner

djezzzl commented Dec 26, 2024

Hi @ducmanh2111,

Thank you for pointing this out!
It should be fixed in the next release: #243

Thank you!

@djezzzl djezzzl closed this as completed Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants