I accidentally added indexes as so:
class AddRandomIndices < ActiveRecord::Migration[5.0]
def change
add_index :charges, :pp_charge_id
add_index :new_refunds, :pp_refund_id
add_index :inventory_items, :product_id, unique: true
add_index :prestock_items, :product_id, unique: true
end
end
Here's the result in schema:
create_table "charges", force: :cascade do |t|
...
t.index ["pp_charge_id"], name: "index_charges_on_pp_charge_id", using: :btree
end
create_table "new_refunds", force: :cascade do |t|
...
t.index ["pp_refund_id"], name: "index_new_refunds_on_pp_refund_id", using: :btree
end
create_table "prestock_items", force: :cascade do |t|
...
t.index ["product_id"], name: "index_prestock_items_on_product_id", unique: true, using: :btree
end
create_table "inventory_items", force: :cascade do |t|
...
t.index ["product_id"], name: "index_inventory_items_on_product_id", unique: true, using: :btree
end
Here's remove file I tried to run:
class RemoveIndex < ActiveRecord::Migration[5.0]
def change
remove_index :charges, :pp_charge_id
remove_index :new_refunds, :pp_refund_id
remove_index :inventory_items, :product_id
remove_index :prestock_items, :product_id
end
end
Here's the error
> rake db:migrate
== 20220515045335 RemoveIndex: migrating ======================================
-- remove_index(:charges, :pp_charge_id)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
No indexes found on charges with the options provided.
In this other SO answer: How to remove index in rails, there are lots of suggested options... none of them worked.
Here I try to run a file where the column and name are explicitly specified
class RemoveIndex < ActiveRecord::Migration[5.0]
def change
remove_index :charges, column: :pp_charge_id, name: :index_charges_on_pp_charge_id
remove_index :new_refunds, column: :pp_refund_id, name: :index_new_refunds_on_pp_refund_id
remove_index :inventory_items, column: :product_id, name: :index_prestock_items_on_product_id
remove_index :prestock_items, column: :product_id, name: :index_inventory_items_on_product_id
end
end
Same error:
> rake db:migrate
== 20220515045335 RemoveIndex: migrating ======================================
-- remove_index(:charges, {:column=>:pp_charge_id, :name=>:index_charges_on_pp_charge_id})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
No indexes found on charges with the options provided.
And then I tried to run the file with just names, no columns
class RemoveIndex < ActiveRecord::Migration[5.0]
def change
remove_index :charges, name: :index_charges_on_pp_charge_id
remove_index :new_refunds, name: :index_new_refunds_on_pp_refund_id
remove_index :inventory_items, name: :index_prestock_items_on_product_id
remove_index :prestock_items, name: :index_inventory_items_on_product_id
end
end
Different error:
> rake db:migrate
== 20220515045335 RemoveIndex: migrating ======================================
-- remove_index(:charges, {:name=>:index_charges_on_pp_charge_id})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedObject: ERROR: index "index_charges_on_pp_charge_id" does not exist
: DROP INDEX "index_charges_on_pp_charge_id"
I've tried passing strings as well, and will spare the continued copy/pasting...
What is happening??!