[INSTRM-1762] current agc_exposure table does not match defined constraints. Created: 19/Oct/22  Updated: 03/Dec/22  Resolved: 03/Dec/22

Status: Done
Project: Instrument control development
Component/s: spt_operational_database
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Normal
Reporter: arnaud.lefur Assignee: arnaud.lefur
Resolution: Done Votes: 0
Labels: EngRun
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Story Points: 2

 Description   

I've bumped into this a few time running alembic on the current summit opdb.
So basically, models.py declare there is a contraint between pfs_visit.pfs_visit_id and agc_exposure_visit_id.

So, that you cannot insert on a pfs_visit_id that does not exist.
This is the right thing to do but, but right now, on the current instance, there is no constraint, so agc_visit.pfs_visit_id can take whatever value, erk...

I cannot easily add the contraint because there is pfs_visit_id in agc_exposure which does not exist in pfs_visit table :

set(agc[:,1]) - set(pfs[:,0])
   {0, 99999, 779594}

From what I understand, cloomis, agc_exposure does not necessarily have a valid pfs_visit, so it's set to 0 in that case, which is fine and we could add that "fake" pfs_visit_id into pfs_visit to respect the constraint. but 99999, 779594 are valid pfs_visit_id and those will eventually exist causing troubles.

Fixing the issue boils down to basically 3 things to do :

  1. setting pfs_visit_id to 0 where pfs_visit_id==99999 or 779594
  2. adding a row in pfs_visit where pfs_visit_id=0
  3. adding the contraint between agc_exposure.pfs_visit_id and pfs_visit.pfs_visit_id


 Comments   
Comment by arnaud.lefur [ 03/Dec/22 ]

We really need to fix this at some point.
Alembic keep screaming about it

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidForeignKey) there is no unique constraint matching given keys for referenced table "agc_exposure"
Generated at Sat Feb 10 16:39:09 JST 2024 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.