Brief Introduction - Data Logic
I am working on a PostgreSQL database that stores experimental data (Raman spectra) and their metadata. In addition to the βnormalβ spectra of our samples, it is necessary to acquire and store special spectra for instrument calibration purposes.
Each time I do an experiment, I create a new record in the measurements table, where I specify the measurement type and the corresponding metadata (foreign keys for other tables).
The problem is that the metadata type differs depending on the measurement type :
- Measurement example - we need to save
sample_id from the samples table - Standard substances - in this case we indicate the substance from the table of
substances - A special standardized light source
source_id must be provided source_id - Dark frames - simple, no data from other tables required
samples, substances and light sources have completely different properties, so we must store them in separate tables associated with the measurements table using foreign keys. I think my data has a polymorphic relationship here (correct me if I am wrong).
Problem
In the current schema, the value stored in the measurementtype_id column (highlighted in red) determines which foreign keys (highlighted in yellow) should be NULL ed and which should contain the value.
Table ratios

I am sure that this design violates the third normal form . We may have a scenario where the wrong type of metadata is associated with a dimension. How can I ensure data integrity? Unfortunately, while I could not find a reasonable solution ...
source share