| 14 | INSERT INTO BiobankSubCategory (id) |
| 15 | SELECT id |
| 16 | FROM BiobankCategory |
| 17 | WHERE id NOT IN ("281", "284", "285") ; |
| 18 | |
| 19 | CREATE TABLE BiobankPersonRole ( |
| 20 | id INTEGER NOT NULL |
| 21 | , PRIMARY KEY(id) |
| 22 | ); |
| 23 | |
| 24 | alter table OntologyTerm modify column __Type enum('OntologyTerm','PersonRole','Species','AlternateId','BiobankCategory','BiobankTopic','BiobankDataType', 'BiobankSubCategory','BiobankPersonRole'); |
| 25 | |
| 26 | |
| 27 | ALTER TABLE Biobank DROP FOREIGN KEY biobank_ibfk_5; |
| 28 | |
| 29 | ALTER TABLE BiobankSubCategory ADD FOREIGN KEY (id) REFERENCES OntologyTerm (id) ON DELETE CASCADE; |
| 30 | |
| 31 | ALTER TABLE `BiobankSubCategory` |
| 32 | ADD CONSTRAINT `biobank_ibfk_5` |
| 33 | FOREIGN KEY (`id`) REFERENCES OntologyTerm (id) ON DELETE CASCADE; AUTO UPARXEI HDH APO THN DHMIOURGIA TOU) |
| 34 | |
| 35 | ALTER TABLE Biobank ADD FOREIGN KEY (SubCategory) REFERENCES BiobankSubCategory (id) ON DELETE RESTRICT; |
| 36 | |
| 37 | ALTER TABLE `Biobank` |
| 38 | ADD CONSTRAINT `biobank_ibfk_885` |
| 39 | FOREIGN KEY (`SubCategory`) REFERENCES BiobankSubCategory (id) ON DELETE CASCADE; |
| 40 | |
| 41 | |
| 42 | |
| 43 | DELETE FROM BiobankCategory |
| 44 | WHERE id NOT IN ("281", "284", "285") ; |
| 45 | |
| 46 | |
| 47 | |
| 48 | ALTER TABLE BiobankPersonRole ADD FOREIGN KEY (id) REFERENCES PersonRole (id) ON DELETE CASCADE; |
| 49 | |
| 50 | |
| 51 | ALTER TABLE `BiobankPersonRole` |
| 52 | ADD CONSTRAINT `BiobankPersonRole_ibfk_33` |
| 53 | FOREIGN KEY (`id`) REFERENCES PersonRole (id) ON DELETE CASCADE; |
| 54 | |
| 55 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='282'; |
| 56 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='283'; |
| 57 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='286'; |
| 58 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='287'; |
| 59 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='288'; |
| 60 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='289'; |
| 61 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='290'; |
| 62 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='291'; |
| 63 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='292'; |
| 64 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='293'; |
| 65 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='295'; |
| 66 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='296'; |
| 67 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='297'; |
| 68 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='298'; |
| 69 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='564'; |
| 70 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='299'; |
| 71 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='294'; |
| 72 | |
| 73 | |
| 74 | |
| 75 | select * from OntologyTerm where name="Software Engineer"; |
| 76 | delete from OntologyTerm where id=561; |
| 77 | select * from BiobankPersonRole; |
| 78 | insert into BiobankPersonRole values(561); |
| 79 | |
| 80 | select * from OntologyTerm where name="coordinator"; |
| 81 | delete from OntologyTerm where id=593; |
| 82 | select * from BiobankPersonRole; |
| 83 | insert into BiobankPersonRole values(277); |
| 84 | |
| 85 | select * from OntologyTerm where name="postdoc"; |
| 86 | delete from OntologyTerm where id=594; |
| 87 | select * from BiobankPersonRole; |
| 88 | insert into BiobankPersonRole values(278); |
| 89 | |
| 90 | select * from OntologyTerm where name="administrator"; |
| 91 | delete from OntologyTerm where id=595; |
| 92 | select * from BiobankPersonRole; |
| 93 | insert into BiobankPersonRole values(279); |
| 94 | |
| 95 | |
| 96 | select * from OntologyTerm where name="IT responsible"; |
| 97 | delete from OntologyTerm where id=596; |
| 98 | select * from BiobankPersonRole; |
| 99 | insert into BiobankPersonRole values(280); |
| 100 | |
| 101 | |
| 102 | COMMIT; |
| 103 | |
| 104 | ====================================================================================== |
| 105 | SubCategory |
| 106 | biobank_ibfk_1 |
| 107 | CONSTRAINT `biobank_ibfk_5` FOREIGN KEY (`SubCategory`) REFERENCES `BiobankSubCategory` (`id`) |
| 108 | CONSTRAINT `biobank_ibfk_5` FOREIGN KEY (`SubCategory`) REFERENCES `BiobankSubCategory` (`id`), |
| 109 | |
| 110 | |
| 111 | =============================WITH COMMENTS =========================================== |
| 112 | |
| 113 | CREATE TABLE `BiobankSubCategory` ( |
| 114 | `id` int(11) NOT NULL, |
| 115 | PRIMARY KEY (`id`), |
| 116 | CONSTRAINT `biobanksubcategory_ibfk_1` FOREIGN KEY (`id`) REFERENCES `OntologyTerm` (`id`) ON DELETE CASCADE |
| 117 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; |
| 118 | |
| 119 | /* move data from BiobankCategory to BiobankSubCategory table */ |
| 120 | INSERT INTO BiobankSubCategory (id) |
| 121 | SELECT id |
| 122 | FROM BiobankCategory |
| 123 | WHERE id NOT IN ("281", "284", "285") ; |
| 124 | /*WHERE name NOT IN ("A. Core Biobanks, DNA available", "B: Supporting biobanks, DNA not yet available" ,"C: Biobanken in opbouw") ;* - IF NEEDED CORRECT THE IDs/ |
| 125 | |
| 126 | /* alter constraints */ |
| 127 | ALTER TABLE Biobank DROP FOREIGN KEY biobank_ibfk_5; |
| 128 | |
| 129 | |
| 130 | ALTER TABLE BiobankSubCategory ADD FOREIGN KEY (id) REFERENCES OntologyTerm (id) ON DELETE CASCADE; |
| 131 | NOT OK : ERROR 1050 (42S01): Table './bbmri/BiobankSubCategory' already exists |
| 132 | THEN USE : |
| 133 | ALTER TABLE `BiobankSubCategory` |
| 134 | ADD CONSTRAINT `id` |
| 135 | FOREIGN KEY (`id`) REFERENCES OntologyTerm (id) ON DELETE CASCADE; |
| 136 | |
| 137 | ALTER TABLE Biobank ADD FOREIGN KEY (SubCategory) REFERENCES BiobankSubCategory (id) ON DELETE RESTRICT; |
| 138 | NOT OK : ERROR 1050 (42S01): Table './bbmri/Biobank' already exists |
| 139 | THEN USE : |
| 140 | ALTER TABLE `Biobank` |
| 141 | ADD CONSTRAINT `SubCategory` |
| 142 | FOREIGN KEY (`SubCategory`) REFERENCES BiobankSubCategory (id) ON DELETE CASCADE; |
| 143 | |
| 144 | |
| 145 | |
| 146 | /* delete moved data from BiobankCategory */ |
| 147 | DELETE FROM BiobankCategory |
| 148 | WHERE id NOT IN ("281", "284", "285") ; |
| 149 | /*IF NEEDED CORRECT THE IDs |
| 150 | WHERE name IN ("A. Core Biobanks, DNA available", "B: Supporting biobanks, DNA not yet available" ,"C: Biobanken in opbouw") ; |
| 151 | */ |
| 152 | |
| 153 | CREATE TABLE BiobankPersonRole ( |
| 154 | id INTEGER NOT NULL |
| 155 | , PRIMARY KEY(id) |
| 156 | ); |
| 157 | |
| 158 | ALTER TABLE BiobankPersonRole ADD FOREIGN KEY (id) REFERENCES PersonRole (id) ON DELETE CASCADE; |
| 159 | |
| 160 | alter table OntologyTerm modify column __Type enum('OntologyTerm','PersonRole','Species','AlternateId','BiobankCategory','BiobankTopic','BiobankDataType', 'BiobankSubCategory','BiobankPersonRole'); |
| 161 | |
| 162 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='282'; |
| 163 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='283'; |
| 164 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='286'; |
| 165 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='287'; |
| 166 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='288'; |
| 167 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='289'; |
| 168 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='290'; |
| 169 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='291'; |
| 170 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='292'; |
| 171 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='293'; |
| 172 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='295'; |
| 173 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='296'; |
| 174 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='297'; |
| 175 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='298'; |
| 176 | UPDATE OntologyTerm SET __Type="BiobankSubCategory" WHERE id='564'; |
| 177 | |
| 178 | /*below we resolve the problem of duplicate entries in ontology term for PersonRole*/ |
| 179 | |
| 180 | select * from OntologyTerm where name="Software Engineer"; |
| 181 | delete from OntologyTerm where id=561; |
| 182 | select * from BiobankPersonRole; |
| 183 | insert into BiobankPersonRole values(561); |
| 184 | |
| 185 | select * from OntologyTerm where name="coordinator"; |
| 186 | delete from OntologyTerm where id=593; |
| 187 | select * from BiobankPersonRole; |
| 188 | insert into BiobankPersonRole values(277); |
| 189 | |
| 190 | select * from OntologyTerm where name="postdoc"; |
| 191 | delete from OntologyTerm where id=594; |
| 192 | select * from BiobankPersonRole; |
| 193 | insert into BiobankPersonRole values(278); |
| 194 | |
| 195 | select * from OntologyTerm where name="administrator"; |
| 196 | delete from OntologyTerm where id=595; |
| 197 | select * from BiobankPersonRole; |
| 198 | insert into BiobankPersonRole values(279); |
| 199 | |
| 200 | |
| 201 | select * from OntologyTerm where name="IT responsible"; |
| 202 | delete from OntologyTerm where id=596; |
| 203 | select * from BiobankPersonRole; |
| 204 | insert into BiobankPersonRole values(280); |
| 205 | |
| 206 | |
| 207 | COMMIT; |
| 208 | |
| 209 | |