Engineering question: Maintaining foreign-key/foreign-key-like relationship between mappings/annotations and variations? #274
Replies: 6 comments
-
|
I think the check constraint is probably the best way to enforce id existence at the database level. I am thinking we could do a query per table when it is needed to search annotations and then go back to what they point to and the type cannot be disambiguated by the id prefix, or if that seems overly brittle. If you query for annotations and then get some object ids, then doing an indexed query against each other object table should be pretty quick, especially compared to the non-indexed query against annotation values you would have just done. e.g. you have annotations like {
"object_id": "ga4gh:VA:123",
"annotation_type": "gnomad-af",
"annotation_value": {
"af": 0.05,
"grpmax-faf": 0.1
}
}If you do a query for |
Beta Was this translation helpful? Give feedback.
-
|
I think we're going with check constraints -- #286 |
Beta Was this translation helpful? Give feedback.
-
|
Unfortunately it looks like you can't write check constraints for one table that reference other tables' columns. Some alternative options:
|
Beta Was this translation helpful? Give feedback.
-
|
This is deeply unsatisfying and I'd really like to return to a better idea later -- but for Jan 15th maybe we just do the hacky thing (separate query beforehand to verify existence of dependent objects) and solve later |
Beta Was this translation helpful? Give feedback.
-
|
I would lean towards, for now, having no constraints for these values, because we are putting values in we know are good and we can trust ourselves at the moment, for the most part. Also in any case, table constraints will slow down write performance so may be an inconvenience in the short term anyways. |
Beta Was this translation helpful? Give feedback.
-
|
The way this problem is typically solved with ORMs is to use inheritance. I would probably opt for joined table inheritance. VrsObject would be the base class. Location and Allele and other variant types would be subclasses. Then you can define Annotation as having a relationship to VrsObject which could be created as a simple foreign key in the database. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Intuitively, we would like to have foreign keys from annotations/mappings back to variations. However, we expect to provide a single table for each type of variation (alleles, CNVs, etc), and it's not particularly straightforward or non-janky to do a foreign key like this. if we don't have this kind of a relationship, then it's possible to add annotations/mappings for variations that aren't contained in the DB, which could be bad.
Beta Was this translation helpful? Give feedback.
All reactions