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

Open
ducmanh2111 opened this issue Aug 23, 2024 · 0 comments
Open

RedundantIndexChecker autofix create incorrect migration #231

ducmanh2111 opened this issue Aug 23, 2024 · 0 comments

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
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