sul-dlss / was-registrar-app

Rails app to organize downloaded web archiving data and trigger preassembly/accessioning when appropriate
0 stars 0 forks source link

Error when adding a pre-existing collection #625

Closed edsu closed 6 months ago

edsu commented 10 months ago

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:

Screen Shot 2024-01-18 at 10 11 47 AM

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

peetucket commented 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:

  1. Add a db constraint explicitly to the app with a new migration
  2. Add a rails validations to the collection model to enforce the uniqueness of the collection druid
mjgiarlo commented 6 months ago

@peetucket and @edsu and @lwrubel determined this is an outdated DB constraint that only lives in prod, so we're going to remove it.

mjgiarlo commented 6 months ago

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)