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

Escape hatch for unsafe migrations #94

Open
guewen opened this issue Jun 6, 2023 · 2 comments
Open

Escape hatch for unsafe migrations #94

guewen opened this issue Jun 6, 2023 · 2 comments

Comments

@guewen
Copy link

guewen commented Jun 6, 2023

Hi!

Some migrations unfortunately cannot be run safely and are then impossible to run.
When using a partitioned table on PostgreSQL, this migration, where slots is the partitioned table, will fail because of 2 Postgres errors:

    add_reference :slots, :variation, index: true, foreign_key: true
  1. ActiveRecord::StatementInvalid: PG::WrongObjectType: ERROR: cannot add NOT VALID foreign key on partitioned table "slots" referencing relation "variations": since validate: false is forced
  2. PG::FeatureNotSupported: ERROR: cannot create index on partitioned table "stock_slots" concurrently : since algorithm: :concurrently is forced

Is there a way to explicitly disable the safeness in a block? If not, what about a block:

  unsafe_migration do
    add_reference :slots, :variation, index: true, foreign_key: true, validate: true
  end

Telling: I know it is not safe, and then it can be caught before deployment to take appropriate measures.

@guewen
Copy link
Author

guewen commented Jun 6, 2023

For the record, I found my way around using 3 distinct commands:

      add_column :slots, :variation_id, :integer
      add_foreign_key :slots, :variations, validate: true
      add_index :slots, :variation_id, algorithm: :default

@rchoquet
Copy link
Contributor

rchoquet commented Jun 8, 2023

Hey @guewen, thanks for taking the time to open this issue.

It's indeed not possible today.
I'd rather give a more explicit name to this method (ex: safe_pg_migrations_disable) like we already do for safe_pg_migrations_verbose.

Do you feel like giving a try at implementing it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants