3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.cdm
.database
.update
.v33_34
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.database
.update
.ColumnAdder
;
19 import eu
.etaxonomy
.cdm
.database
.update
.ColumnNameChanger
;
20 import eu
.etaxonomy
.cdm
.database
.update
.ColumnRemover
;
21 import eu
.etaxonomy
.cdm
.database
.update
.ColumnTypeChanger
;
22 import eu
.etaxonomy
.cdm
.database
.update
.ISchemaUpdater
;
23 import eu
.etaxonomy
.cdm
.database
.update
.ISchemaUpdaterStep
;
24 import eu
.etaxonomy
.cdm
.database
.update
.SchemaUpdaterBase
;
25 import eu
.etaxonomy
.cdm
.database
.update
.SimpleSchemaUpdaterStep
;
26 import eu
.etaxonomy
.cdm
.database
.update
.TableCreator
;
27 import eu
.etaxonomy
.cdm
.database
.update
.TableDroper
;
28 import eu
.etaxonomy
.cdm
.database
.update
.v31_33
.SchemaUpdater_33_331
;
32 * @created Jan 14, 2014
34 public class SchemaUpdater_331_34
extends SchemaUpdaterBase
{
36 @SuppressWarnings("unused")
37 private static final Logger logger
= Logger
.getLogger(SchemaUpdater_331_34
.class);
38 private static final String startSchemaVersion
= "3.3.1.0.201401140000";
39 private static final String endSchemaVersion
= "3.4.0.0.201407010000";
41 // ********************** FACTORY METHOD *************************************
43 public static SchemaUpdater_331_34
NewInstance() {
44 return new SchemaUpdater_331_34();
48 * @param startSchemaVersion
49 * @param endSchemaVersion
51 protected SchemaUpdater_331_34() {
52 super(startSchemaVersion
, endSchemaVersion
);
56 protected List
<ISchemaUpdaterStep
> getUpdaterList() {
60 ISchemaUpdaterStep step
;
65 List
<ISchemaUpdaterStep
> stepList
= new ArrayList
<ISchemaUpdaterStep
>();
67 //TODO H2 / PostGreSQL / SQL Server
69 stepName
= "Update User unique indexes";
70 tableName
= "UserAccount";
71 columnName
= "username";
72 step
= UsernameConstraintUpdater
.NewInstance(stepName
, tableName
, columnName
);
75 //TODO H2 / PostGreSQL / SQL Server
76 //PermissionGroup unique
77 stepName
= "Update Group unique indexes";
78 tableName
= "PermissionGroup";
80 step
= UsernameConstraintUpdater
.NewInstance(stepName
, tableName
, columnName
);
83 //TODO H2 / PostGreSQL / SQL Server
84 //GrantedAuthority unique
85 stepName
= "Update User unique indexes";
86 tableName
= "GrantedAuthorityImpl";
87 columnName
= "authority";
88 step
= UsernameConstraintUpdater
.NewInstance(stepName
, tableName
, columnName
);
91 //TODO H2 / PostGreSQL / SQL Server
92 stepName
= "Add label column to derived unit";
93 tableName
= "SpecimenOrObservationBase";
94 columnName
= "originalLabelInfo";
95 step
= ColumnAdder
.NewClobInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
);
99 //TODO test with data and H2 / PostGreSQL / SQL Server
100 //set default value to true where required
101 stepName
= "Set publish to true if null";
102 String query
= " UPDATE @@TaxonBase@@ " +
103 " SET publish = @TRUE@ " +
104 " WHERE DTYPE IN ('Synonym') AND publish IS NULL ";
105 step
= SimpleSchemaUpdaterStep
.NewAuditedInstance(stepName
, query
, "TaxonBase", 99);
109 addIdentifierTables(stepList
);
112 //remove series from Reference #4293
113 stepName
= "Copy series to series part";
114 String sql
= " UPDATE Reference r " +
115 " SET r.seriespart = r.series " +
116 " WHERE r.series is NOT NULL AND r.seriesPart IS NULL ";
117 step
= SimpleSchemaUpdaterStep
.NewAuditedInstance(stepName
, sql
, "Reference", 99);
120 stepName
= "Set series to NULL";
121 sql
= " UPDATE Reference r " +
122 " SET r.series = NULL " +
123 " WHERE r.series = r.seriesPart ";
124 step
= SimpleSchemaUpdaterStep
.NewAuditedInstance(stepName
, sql
, "Reference", 99);
127 //TODO check all series are null
129 stepName
= "Remove series column";
130 tableName
= "Reference";
131 oldColumnName
= "series";
132 step
= ColumnRemover
.NewInstance(stepName
, tableName
, oldColumnName
, INCLUDE_AUDIT
);
135 //authorTeam -> authorship
136 stepName
= "Rename Reference.authorTeam column";
137 tableName
= "Reference";
138 oldColumnName
= "authorTeam_id";
139 newColumnName
= "authorship_id";
140 step
= ColumnNameChanger
.NewIntegerInstance(stepName
, tableName
, oldColumnName
, newColumnName
, INCLUDE_AUDIT
);
143 //remove CDM_VIEW #4316
144 stepName
= "Remove CDM_VIEW_CDM_VIEW table";
145 tableName
= "CDM_VIEW_CDM_VIEW";
146 boolean ifExists
= true;
147 step
= TableDroper
.NewInstance(stepName
, tableName
, ! INCLUDE_AUDIT
, ifExists
);
150 stepName
= "Remove CDM_VIEW table";
151 tableName
= "CDM_VIEW";
153 step
= TableDroper
.NewInstance(stepName
, tableName
, ! INCLUDE_AUDIT
, ifExists
);
157 //TODO not null on username, groupname and authority #4382
161 stepName
= "Create dna quality";
162 boolean includeCdmBaseAttributes
= true;
163 tableName
= "DnaQuality";
164 String
[] columnNames
= new String
[]{"purificationmethod","concentration","ratioofabsorbance260_230", "ratioofabsorbance260_280","qualitycheckdate","concentrationunit_id","qualityterm_id"};
165 String
[] columnTypes
= new String
[]{"string_255","double","double","double","datetime","int","int"};
166 String
[] referencedTables
= new String
[]{null,null,null,null,null,"DefinedTermBase","DefinedTermBase"};
167 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
170 //DnaQuality in TissueSample
171 //TODO H2 / PostGreSQL / SQL Server
172 stepName
= "Add foreign key to dna quality";
173 tableName
= "SpecimenOrObservationBase";
174 newColumnName
= "dnaQuality_id";
175 boolean notNull
= false;
176 String referencedTable
= "DnaQuality";
177 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, newColumnName
, INCLUDE_AUDIT
, notNull
, referencedTable
);
180 //time scope for classifications
181 //TODO H2 / PostGreSQL / SQL Server
182 stepName
= "Add time scope (start) for classifications";
183 tableName
= "Classification";
184 newColumnName
= "timeperiod_start";
186 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, newColumnName
, length
, INCLUDE_AUDIT
);
189 //TODO H2 / PostGreSQL / SQL Server
190 stepName
= "Add time scope (end) for classifications";
191 tableName
= "Classification";
192 newColumnName
= "timeperiod_end";
194 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, newColumnName
, length
, INCLUDE_AUDIT
);
197 //TODO H2 / PostGreSQL / SQL Server
198 stepName
= "Add time scope (freetext) for classifications";
199 tableName
= "Classification";
200 newColumnName
= "timeperiod_freetext";
202 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, newColumnName
, length
, INCLUDE_AUDIT
);
205 //Classification_GeoScope
206 stepName
= "Create Classification_GeoScope table";
207 includeCdmBaseAttributes
= false;
208 tableName
= "Classification_GeoScope";
209 columnNames
= new String
[]{"Classification_id","geoScopes_id"};
210 columnTypes
= new String
[]{"int","int"};
211 referencedTables
= new String
[]{"Classification","DefinedTermBase"};
212 TableCreator creator
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
213 creator
.setPrimaryKeyParams("Classification_id,geoScopes_id", "REV,Classification_id,geoScopes_id");
214 stepList
.add(creator
);
216 //Classification_Description
217 stepName
= "Create Classification_Description table";
218 includeCdmBaseAttributes
= false;
219 tableName
= "Classification_Description";
220 columnNames
= new String
[]{"Classification_id","description_id","description_mapkey_id"};
221 columnTypes
= new String
[]{"int","int","int"};
222 referencedTables
= new String
[]{"Classification","LanguageString","DefinedTermBase"};
223 creator
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
224 creator
.setPrimaryKeyParams("Classification_id", "REV,Classification_id,description_id,description_mapkey_id");
225 stepList
.add(creator
);
227 //Primer.sequence type #4139
228 stepName
= "Add sequence string column to primer";
229 tableName
= "Primer";
230 newColumnName
= "sequence_string";
231 step
= ColumnAdder
.NewClobInstance(stepName
, tableName
, newColumnName
,
235 //Primer.sequence length #4139
236 stepName
= "Add sequence length column to primer";
237 tableName
= "Primer";
238 newColumnName
= "sequence_length";
240 referencedTable
= null;
241 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, newColumnName
, INCLUDE_AUDIT
, null, notNull
);
244 //EntityValidationResult
245 stepName
= "Create EntityValidationResult table";
246 includeCdmBaseAttributes
= true;
247 tableName
= "EntityValidationResult";
248 columnNames
= new String
[]{"crudeventtype","userfriendlydescription","userfriendlytypename",
249 "validatedentityclass","validatedentityid","validatedentityuuid"};
250 columnTypes
= new String
[]{"string_255","string_255","string_255","string_255","int","string_36"};
251 referencedTables
= new String
[]{null,null,null,null,null,null};
252 creator
= TableCreator
.NewNonVersionableInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, ! INCLUDE_AUDIT
);
253 stepList
.add(creator
);
255 //EntityConstraintViolation
256 stepName
= "Create EntityConstraintViolation table";
257 includeCdmBaseAttributes
= true;
258 tableName
= "EntityConstraintViolation";
259 columnNames
= new String
[]{"invalidvalue","message","propertypath","severity","userfriendlyfieldname",
260 "validator","entityvalidationresult_id"};
261 columnTypes
= new String
[]{"string_255","string_255","string_255","string_255","string_255","string_255","int"};
262 referencedTables
= new String
[]{null,null,null,null,null,null,"EntityValidationResult"};
263 creator
= TableCreator
.NewNonVersionableInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, ! INCLUDE_AUDIT
);
264 stepList
.add(creator
);
266 //make OriginalSourceBase.sourceType allow NULL
267 stepName
= "Remove NOT NULL from sourceType";
268 tableName
= "OriginalSourceBase_AUD";
269 oldColumnName
= "sourceType";
270 // query = "ALTER TABLE OriginalSourceBase_AUD " +
271 // " CHANGE COLUMN sourceType sourceType VARCHAR(4) NULL ";
272 step
= ColumnTypeChanger
.NewStringSizeInstance(stepName
, tableName
, oldColumnName
, 4, ! INCLUDE_AUDIT
);
276 //remove sequence_id column //we do not move data as we do not expect data available yet #4139
277 //we put this to the end as it seems to fail with INNODB
278 stepName
= "Remove sequence_id column from primer";
279 tableName
= "Primer";
280 oldColumnName
= "sequence_id";
281 step
= ColumnRemover
.NewInstance(stepName
, tableName
, oldColumnName
, INCLUDE_AUDIT
);
285 // WE REMOVED THIS FROM THE SCRIPT BECAUSE IT FAILS WITH INNODB
286 // //change size of AgentBase_contact_urls.contact_urls_element #3920
287 // stepName = "Change length of AgentBase_contact_urls.contact_urls_element";
288 // tableName = "AgentBase_contact_urls";
289 // columnName = "contact_urls_element";
290 // step = ColumnTypeChanger.NewStringSizeInstance(stepName, tableName,
291 // columnName, 330, INCLUDE_AUDIT);
292 //// stepList.add(step);
299 private void addIdentifierTables(List
<ISchemaUpdaterStep
> stepList
) {
302 String stepName
= "Create Identifier table";
303 boolean includeCdmBaseAttributes
= true;
304 String tableName
= "Identifier";
305 String
[] columnNames
= new String
[]{"identifier","identifiedObj_type", "identifiedObj_id","type_id"};
306 String
[] columnTypes
= new String
[]{"string_800","string_255","int","int"};
307 String
[] referencedTables
= new String
[]{null,null,null,"DefinedTermBase"};
308 TableCreator step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
311 //AgentBase_Identifier
312 stepName
= "Create AgentBase_Identifier table";
313 includeCdmBaseAttributes
= false;
314 tableName
= "AgentBase_Identifier";
315 columnNames
= new String
[]{"AgentBase_id","identifiers_id","sortIndex"};
316 columnTypes
= new String
[]{"int","int","int"};
317 referencedTables
= new String
[]{"AgentBase","Identifier",null};
318 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
319 step
.setPrimaryKeyParams("AgentBase_id,identifiers_id", "REV,AgentBase_id,identifiers_id");
322 //Classification_Identifier
323 stepName
= "Create Classification_Identifier table";
324 includeCdmBaseAttributes
= false;
325 tableName
= "Classification_Identifier";
326 columnNames
= new String
[]{"Classification_id","identifiers_id","sortIndex"};
327 columnTypes
= new String
[]{"int","int","int"};
328 referencedTables
= new String
[]{"Classification","Identifier",null};
329 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
330 step
.setPrimaryKeyParams("Classification_id,identifiers_id", "REV,Classification_id,identifiers_id");
333 //Collection_Identifier
334 stepName
= "Create Collection_Identifier table";
335 includeCdmBaseAttributes
= false;
336 tableName
= "Collection_Identifier";
337 columnNames
= new String
[]{"Collection_id","identifiers_id","sortIndex"};
338 columnTypes
= new String
[]{"int","int","int"};
339 referencedTables
= new String
[]{"Collection","Identifier",null};
340 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
341 step
.setPrimaryKeyParams("Collection_id,identifiers_id", "REV,Collection_id,identifiers_id");
344 //DefinedTermBase_Identifier
345 stepName
= "Create DefinedTermBase_Identifier table";
346 includeCdmBaseAttributes
= false;
347 tableName
= "DefinedTermBase_Identifier";
348 columnNames
= new String
[]{"DefinedTermBase_id","identifiers_id","sortIndex"};
349 columnTypes
= new String
[]{"int","int","int"};
350 referencedTables
= new String
[]{"DefinedTermBase","Identifier",null};
351 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
352 step
.setPrimaryKeyParams("DefinedTermBase_id,identifiers_id", "REV,DefinedTermBase_id,identifiers_id");
355 //DescriptionBase_Identifier
356 stepName
= "Create DescriptionBase_Identifier table";
357 includeCdmBaseAttributes
= false;
358 tableName
= "DescriptionBase_Identifier";
359 columnNames
= new String
[]{"DescriptionBase_id","identifiers_id","sortIndex"};
360 columnTypes
= new String
[]{"int","int","int"};
361 referencedTables
= new String
[]{"DescriptionBase","Identifier",null};
362 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
363 step
.setPrimaryKeyParams("DescriptionBase_id,identifiers_id", "REV,DescriptionBase_id,identifiers_id");
366 //FeatureTree_Identifier
367 stepName
= "Create FeatureTree_Identifier table";
368 includeCdmBaseAttributes
= false;
369 tableName
= "FeatureTree_Identifier";
370 columnNames
= new String
[]{"FeatureTree_id","identifiers_id","sortIndex"};
371 columnTypes
= new String
[]{"int","int","int"};
372 referencedTables
= new String
[]{"FeatureTree","Identifier",null};
373 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
374 step
.setPrimaryKeyParams("FeatureTree_id,identifiers_id", "REV,FeatureTree_id,identifiers_id");
378 stepName
= "Create Media_Identifier table";
379 includeCdmBaseAttributes
= false;
380 tableName
= "Media_Identifier";
381 columnNames
= new String
[]{"Media_id","identifiers_id","sortIndex"};
382 columnTypes
= new String
[]{"int","int","int"};
383 referencedTables
= new String
[]{"Media","Identifier",null};
384 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
385 step
.setPrimaryKeyParams("Media_id,identifiers_id", "REV,Media_id,identifiers_id");
388 //PolytomousKey_Identifier
389 stepName
= "Create PolytomousKey_Identifier table";
390 includeCdmBaseAttributes
= false;
391 tableName
= "PolytomousKey_Identifier";
392 columnNames
= new String
[]{"PolytomousKey_id","identifiers_id","sortIndex"};
393 columnTypes
= new String
[]{"int","int","int"};
394 referencedTables
= new String
[]{"PolytomousKey","Identifier",null};
395 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
396 step
.setPrimaryKeyParams("PolytomousKey_id,identifiers_id", "REV,PolytomousKey_id,identifiers_id");
399 //Reference_Identifier
400 stepName
= "Create Reference_Identifier table";
401 includeCdmBaseAttributes
= false;
402 tableName
= "Reference_Identifier";
403 columnNames
= new String
[]{"Reference_id","identifiers_id","sortIndex"};
404 columnTypes
= new String
[]{"int","int","int"};
405 referencedTables
= new String
[]{"Reference","Identifier",null};
406 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
407 step
.setPrimaryKeyParams("Reference_id,identifiers_id", "REV,Reference_id,identifiers_id");
410 //SpecimenOrObservationBase_Identifier
411 stepName
= "Create SpecimenOrObservationBase_Identifier table";
412 includeCdmBaseAttributes
= false;
413 tableName
= "SpecimenOrObservationBase_Identifier";
414 columnNames
= new String
[]{"SpecimenOrObservationBase_id","identifiers_id","sortIndex"};
415 columnTypes
= new String
[]{"int","int","int"};
416 referencedTables
= new String
[]{"SpecimenOrObservationBase","Identifier",null};
417 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
418 step
.setPrimaryKeyParams("SpecimenOrObservationBase_id,identifiers_id", "REV,SpecimenOrObservationBase_id,identifiers_id");
421 //TaxonBase_Identifier
422 stepName
= "Create TaxonBase_Identifier table";
423 includeCdmBaseAttributes
= false;
424 tableName
= "TaxonBase_Identifier";
425 columnNames
= new String
[]{"TaxonBase_id","identifiers_id","sortIndex"};
426 columnTypes
= new String
[]{"int","int","int"};
427 referencedTables
= new String
[]{"TaxonBase","Identifier",null};
428 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
429 step
.setPrimaryKeyParams("TaxonBase_id,identifiers_id", "REV,TaxonBase_id,identifiers_id");
432 //TaxonNameBase_Identifier
433 stepName
= "Create TaxonNameBase_Identifier table";
434 includeCdmBaseAttributes
= false;
435 tableName
= "TaxonNameBase_Identifier";
436 columnNames
= new String
[]{"TaxonNameBase_id","identifiers_id","sortIndex"};
437 columnTypes
= new String
[]{"int","int","int"};
438 referencedTables
= new String
[]{"TaxonNameBase","Identifier",null};
439 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
440 step
.setPrimaryKeyParams("TaxonNameBase_id,identifiers_id", "REV,TaxonNameBase_id,identifiers_id");
443 //TermVocabulary_Identifier
444 stepName
= "Create TermVocabulary_Identifier table";
445 includeCdmBaseAttributes
= false;
446 tableName
= "TermVocabulary_Identifier";
447 columnNames
= new String
[]{"TermVocabulary_id","identifiers_id","sortIndex"};
448 columnTypes
= new String
[]{"int","int","int"};
449 referencedTables
= new String
[]{"TermVocabulary","Identifier",null};
450 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
451 step
.setPrimaryKeyParams("TermVocabulary_id,identifiers_id", "REV,TermVocabulary_id,identifiers_id");
457 public ISchemaUpdater
getNextUpdater() {
458 return SchemaUpdater_34_341
.NewInstance();
462 public ISchemaUpdater
getPreviousUpdater() {
463 return SchemaUpdater_33_331
.NewInstance();