Closed benjie closed 2 years ago
I'm going to add some notes below on other ways the schema could be improved by adding constraints; I hope that's okay!
study --- participant_flows is a one-to-one relationship:
ALTER TABLE participant_flows ADD UNIQUE (nct_id);
Some of the foreign keys are missing indexes:
CREATE INDEX ON reported_events (result_group_id);
CREATE INDEX ON outcome_measurements (result_group_id);
CREATE INDEX ON outcome_measurements (outcome_id);
CREATE INDEX ON baseline_measurements (result_group_id);
CREATE INDEX ON design_group_interventions (intervention_id);
CREATE INDEX ON design_group_interventions (design_group_id);
CREATE INDEX ON outcome_counts (outcome_id);
CREATE INDEX ON outcome_counts (result_group_id);
CREATE INDEX ON milestones (result_group_id);
CREATE INDEX ON outcome_analysis_groups (result_group_id);
CREATE INDEX ON outcome_analysis_groups (outcome_analysis_id);
CREATE INDEX ON facility_contacts (facility_id);
CREATE INDEX ON drop_withdrawals (result_group_id);
CREATE INDEX ON intervention_other_names (intervention_id);
CREATE INDEX ON facility_investigators (facility_id);
CREATE INDEX ON outcome_analyses (outcome_id);
CREATE INDEX ON baseline_counts (result_group_id);
This is great! Thanks so much. You're absolutely right - this is something we need to do. We've added your notes to a jira ticket and intend to do this in the next release (after the one that's about to go out). Really appreciate your input. Thank you.
This is an incredible resource - thanks!
The database at the moment lacks a primary key on the
studies
table, and has no foreign keys defined which makes it more challenging to use certain tooling against (for example database visualisations). Also most of the columns are nullable, when many need not be.I include below SQL required to convert the
studies
unique index into a primary key, set the referencing columns non-null, and create the missing foreign keys. I've tested this locally against the latest dump20181111
. The SQL was mostly auto-generated, so I've included the SQL I used to generate the statements to make it easy to update in future.I would be happy to send a pull request creating the relevant migration file in ruby if this is something that's likely to be merged?
Thanks again!