activerecord-cockroachdb-adapter
activerecord-cockroachdb-adapter copied to clipboard
Remove uniq index
Hello,
I try to remove a uniq index:
add_index :foo, :foo_token unique: true
with
remove_index :foo, name: :foo_token
and I get
-- remove_index(:foo, {:name=>:foo_token})
/usr/local/bundle/gems/prometheus_exporter-2.0.8/lib/prometheus_exporter/instrumentation/method_profiler.rb:97:in `exec': PG::DependentObjectsStillExist: ERROR: index "foo_token" is in use as unique constraint (ActiveRecord::StatementInvalid)
HINT: use CASCADE if you really want to drop it.
/usr/local/bundle/gems/prometheus_exporter-2.0.8/lib/prometheus_exporter/instrumentation/method_profiler.rb:97:in `exec': ERROR: index "foo_token" is in use as unique constraint (PG::DependentObjectsStillExist)
HINT: use CASCADE if you really want to drop it.
Problem:
locally it works fine. But I do not see the uniq constraint in the schema.rb. So maybe it works fine locally, because the constraint is missing. But on staging/production not.
Hi @Piioo,
Unfortunately, I don’t have access to my computer now and cannot fully help you. However, we might succeed together.
First, to confirm the issue, have you tried the two next items ?
- With a rails/pg configuration, see if you have a similar error.
- Within the current configuration trying
remove_index :foo, :foo_token, unique: true
Unfortunately I think this won’t indeed be enough. Hence if it isn’t, the next step would be for you to contribute.
For this you’d have to be clear on the behavior of the abstract remove_index method.
Then take a look on how you can remove a constraint with crdb. And create the corresponding method in the adapter.
Of course add some tests and we’d be ready! Otherwise I’ll work on that, likely in January.
@rafiss do you know why we don’t allow this behavior in CRDB?