Closed edsu closed 6 months ago
It's not clear to me where this database constraint is coming from. I indeed see it on the prod psql server, but I do not see it in schema.rb file or any of the migrations. I was able to add the same collection druid twice on my laptop without issue.
We do have a Rails validation that ensures the combination of three fields are unique and this works as expected in localhost and also matches the database constraint identified in the schema.rb:
Rails validation:
validates_uniqueness_of :wasapi_collection_id,
scope: %i[wasapi_provider wasapi_account],
message: 'already have a collection configured for this WASAPI collection'
Associated DB constraint:
t.index ["wasapi_provider", "wasapi_account", "wasapi_collection_id"], name: "index_collections_on_wasapi", unique: true
DB contraint that is causing issue on the prod server, which I cannot find in the app anywhere:
psql ...
SELECT indexname, tablename, indexdef FROM pg_indexes;
.....
index_collections_on_druid | collections | CREATE UNIQUE INDEX index_collections_on_druid ON public.collections USING btree (druid)
.....
So if this is a real constraint we need, we may want to:
@peetucket and @edsu and @lwrubel determined this is an outdated DB constraint that only lives in prod, so we're going to remove it.
This is now done in prod:
was=# SELECT indexname, tablename FROM pg_indexes WHERE tablename = 'collections';
indexname | tablename
-----------------------------+-------------
collections_pkey | collections
index_collections_on_druid | collections
index_collections_on_wasapi | collections
(3 rows)
was=# DROP INDEX index_collections_on_druid;
DROP INDEX
was=# SELECT indexname, tablename FROM pg_indexes WHERE tablename = 'collections';
indexname | tablename
-----------------------------+-------------
collections_pkey | collections
index_collections_on_wasapi | collections
(2 rows)
If a user tries to add a new collection using the form at https://was-registrar-app.stanford.edu/collections/new and the DRUID for the collection already exists in the was-registrar-app database, the app blows up with an opaque error message:
It would be more helpful to see an error message about how the collection already exists, and be presented for a link to it.
See https://app.honeybadger.io/projects/63547/faults/95901548