|
| 1 | +-- To undo: |
| 2 | +-- drop table BLSample_has_Ligand; |
| 3 | +-- drop table Ligand_has_PDB |
| 4 | +-- drop table Ligand; |
| 5 | +-- delete from SchemaStatus where scriptName = '2025_05_23_Ligand_and_junction_tables.sql'; |
| 6 | + |
| 7 | + |
| 8 | +INSERT IGNORE INTO SchemaStatus (scriptName, schemaStatus) VALUES ('2025_05_23_Ligand_and_junction_tables.sql', 'ONGOING'); |
| 9 | + |
| 10 | +CREATE TABLE Ligand ( |
| 11 | + ligandId int(11) unsigned PRIMARY KEY AUTO_INCREMENT, |
| 12 | + proposalId int(10) unsigned NOT NULL COMMENT 'References Proposal table', |
| 13 | + name varchar(30) NOT NULL COMMENT 'Ligand name', |
| 14 | + SMILES varchar(400) COMMENT 'Chemical structure', |
| 15 | + libraryName varchar(30) COMMENT 'Name of ligand library, to preserve provenance', |
| 16 | + libraryBatchNumber varchar(30) COMMENT 'Batch number of library, to preserve provenance', |
| 17 | + plateBarcode varchar(30) COMMENT 'Specific barcode of the plate it came from, to preserve provenance', |
| 18 | + sourceWell varchar(30) COMMENT 'Location within that plate, to preserve provenance', |
| 19 | + CONSTRAINT `Ligand_fk_proposalId` |
| 20 | + FOREIGN KEY (proposalId) |
| 21 | + REFERENCES Proposal (proposalId) |
| 22 | + ON DELETE CASCADE |
| 23 | + ON UPDATE CASCADE |
| 24 | +) COMMENT = 'Ligands in biochemistry are substances that bind to biomolecules'; |
| 25 | + |
| 26 | +CREATE TABLE BLSample_has_Ligand ( |
| 27 | + blSampleId int(10) unsigned, |
| 28 | + ligandId int(11) unsigned, |
| 29 | + PRIMARY KEY (blSampleId, ligandId), |
| 30 | + CONSTRAINT BLSample_has_Ligand_fk1 |
| 31 | + FOREIGN KEY (blSampleId) |
| 32 | + REFERENCES BLSample (blSampleId) |
| 33 | + ON DELETE CASCADE |
| 34 | + ON UPDATE CASCADE, |
| 35 | + CONSTRAINT BLSample_has_Ligand_fk2 |
| 36 | + FOREIGN KEY (ligandId) |
| 37 | + REFERENCES Ligand (ligandId) |
| 38 | + ON DELETE CASCADE |
| 39 | + ON UPDATE CASCADE |
| 40 | +) COMMENT = 'Junction table for BLSample and Ligand'; |
| 41 | + |
| 42 | +CREATE TABLE Ligand_has_PDB ( |
| 43 | + ligandId int(11) unsigned, |
| 44 | + pdbId int(11) unsigned, |
| 45 | + PRIMARY KEY (ligandId, pdbId), |
| 46 | + CONSTRAINT Ligand_Has_PDB_fk1 |
| 47 | + FOREIGN KEY (ligandId) |
| 48 | + REFERENCES Ligand (ligandId) |
| 49 | + ON DELETE CASCADE |
| 50 | + ON UPDATE CASCADE, |
| 51 | + CONSTRAINT Ligand_Has_PDB_fk2 |
| 52 | + FOREIGN KEY (pdbid) |
| 53 | + REFERENCES PDB (pdbId) |
| 54 | + ON DELETE CASCADE |
| 55 | + ON UPDATE CASCADE |
| 56 | +) COMMENT = 'Junction table for Ligand and PDB'; |
| 57 | + |
| 58 | +UPDATE SchemaStatus SET schemaStatus = 'DONE' WHERE scriptName = '2025_05_23_Ligand_and_junction_tables.sql'; |
0 commit comments