Skip to content

Escape hatch for unsafe migrations  #94

@guewen

Description

@guewen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions