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

add_reference + index +disable_ddl_transaction! is an unsafe pattern? #240

Closed
DmitryTsepelev opened this issue Aug 30, 2023 · 1 comment
Closed

Comments

@DmitryTsepelev
Copy link

Hey!

Looks like I found an interesting behavior:

class Something < ActiveRecord::Migration[7.0]
  disable_ddl_transaction!

  def change
    add_reference :users, :email, index: { algorithm: :concurrently }
  end
end

Effectively it does the following:

  1. turns off the transaction (for index)
  2. adds column
  3. creates index

However, if something goes wrong and migration will fail during the index creation—there will be a weird state: migration is rolled back, column is created, index is not created/created with error.

Do I miss something? I'd be happy to add a new rule for that

@DmitryTsepelev DmitryTsepelev changed the title add_reference + index +disable_ddl_transaction! add_reference + index +disable_ddl_transaction! is an unsafe pattern? Aug 30, 2023
@ankane
Copy link
Owner

ankane commented Aug 30, 2023

Hi @DmitryTsepelev, see #202 for a previous discussion.

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

2 participants