Skip to content

Can't disable concurrent index creation with Rails 7.1? #154

@jordan-brough

Description

@jordan-brough

In a Rails 7.1 application, if I try to supply algorithm: :default to add_index:

add_index :some_table, [:some_column], algorithm: :default

then I get an error like this:

StandardError: An error has occurred, all later migrations canceled: (StandardError)

Algorithm must be one of the following: :concurrently
ruby/3.3.6/lib/ruby/gems/3.3.0/gems/activerecord-7.1.5.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1470:in `block in index_algorithm'
ruby/3.3.6/lib/ruby/gems/3.3.0/gems/activerecord-7.1.5.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1469:in `fetch'

iiuc, Rails is hitting that check & error condition before this safe-pg-migrations code can kick in:

def add_index(table_name, column_name, **options)
if options[:algorithm] == :default
options.delete :algorithm
else
options[:algorithm] = :concurrently
end

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