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
42 // *******************************************
44 public static SchemaUpdater_331_34
NewInstance() {
45 return new SchemaUpdater_331_34();
49 * @param startSchemaVersion
50 * @param endSchemaVersion
52 protected SchemaUpdater_331_34() {
53 super(startSchemaVersion
, endSchemaVersion
);
57 protected List
<ISchemaUpdaterStep
> getUpdaterList() {
61 ISchemaUpdaterStep step
;
64 List
<ISchemaUpdaterStep
> stepList
= new ArrayList
<ISchemaUpdaterStep
>();
66 //TODO H2 / PostGreSQL / SQL Server
68 stepName
= "Update User unique indexes";
69 tableName
= "UserAccount";
70 columnName
= "username";
71 step
= UsernameConstraintUpdater
.NewInstance(stepName
, tableName
, columnName
);
74 //TODO H2 / PostGreSQL / SQL Server
75 //PermissionGroup unique
76 stepName
= "Update Group unique indexes";
77 tableName
= "PermissionGroup";
79 step
= UsernameConstraintUpdater
.NewInstance(stepName
, tableName
, columnName
);
82 //TODO H2 / PostGreSQL / SQL Server
83 //GrantedAuthority unique
84 stepName
= "Update User unique indexes";
85 tableName
= "GrantedAuthorityImpl";
86 columnName
= "authority";
87 step
= UsernameConstraintUpdater
.NewInstance(stepName
, tableName
, columnName
);
90 //TODO H2 / PostGreSQL / SQL Server
91 stepName
= "Add label column to derived unit";
92 tableName
= "SpecimenOrObservationBase";
93 columnName
= "originalLabelInfo";
94 step
= ColumnAdder
.NewClobInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
);
98 //TODO test with data and H2 / PostGreSQL / SQL Server
99 //set default value to true where required
100 stepName
= "Set publish to true if null";
101 String query
= " UPDATE @@TaxonBase@@ " +
102 " SET publish = @TRUE@ " +
103 " WHERE DTYPE IN ('Synonym') AND publish IS NULL ";
104 step
= SimpleSchemaUpdaterStep
.NewAuditedInstance(stepName
, query
, "TaxonBase", 99);
108 addIdentifierTables(stepList
);
111 //remove series from Reference #4293
112 stepName
= "Copy series to series part";
113 String sql
= " UPDATE Reference r " +
114 " SET r.seriespart = r.series " +
115 " WHERE r.series is NOT NULL AND r.seriesPart IS NULL ";
116 step
= SimpleSchemaUpdaterStep
.NewAuditedInstance(stepName
, sql
, "Reference", 99);
119 stepName
= "Set series to NULL";
120 sql
= " UPDATE Reference r " +
121 " SET r.series = NULL " +
122 " WHERE r.series = r.seriesPart ";
123 step
= SimpleSchemaUpdaterStep
.NewAuditedInstance(stepName
, sql
, "Reference", 99);
126 //TODO check all series are null
128 stepName
= "Remove series column";
129 tableName
= "Reference";
130 String oldColumnName
= "series";
131 step
= ColumnRemover
.NewInstance(stepName
, tableName
, oldColumnName
, INCLUDE_AUDIT
);
134 //authorTeam -> authorship
135 stepName
= "Rename Reference.authorTeam column";
136 tableName
= "Reference";
137 oldColumnName
= "authorTeam_id";
138 String newColumnName
= "authorship_id";
139 step
= ColumnNameChanger
.NewIntegerInstance(stepName
, tableName
, oldColumnName
, newColumnName
, INCLUDE_AUDIT
);
142 //remove CDM_VIEW #4316
143 stepName
= "Remove CDM_VIEW_CDM_VIEW table";
144 tableName
= "CDM_VIEW_CDM_VIEW";
145 boolean ifExists
= true;
146 step
= TableDroper
.NewInstance(stepName
, tableName
, ! INCLUDE_AUDIT
, ifExists
);
149 stepName
= "Remove CDM_VIEW table";
150 tableName
= "CDM_VIEW";
152 step
= TableDroper
.NewInstance(stepName
, tableName
, ! INCLUDE_AUDIT
, ifExists
);
155 //change size of AgentBase_contact_urls.contact_urls_element #3920
156 stepName
= "Change length of AgentBase_contact_urls.contact_urls_element";
157 tableName
= "AgentBase_contact_urls";
158 columnName
= "contact_urls_element";
159 step
= ColumnTypeChanger
.NewStringSizeInstance(stepName
, tableName
,
160 columnName
, 330, INCLUDE_AUDIT
);
163 //TODO not null on username, groupname and authority #4382
167 stepName
= "Create dna quality";
168 boolean includeCdmBaseAttributes
= true;
169 tableName
= "DnaQuality";
170 String
[] columnNames
= new String
[]{"purificationmethod","concentration","ratioofabsorbance260_230", "ratioofabsorbance260_280","qualitycheckdate","concentrationunit_id","qualityterm_id"};
171 String
[] columnTypes
= new String
[]{"string_255","double","double","double","datetime","int","int"};
172 String
[] referencedTables
= new String
[]{null,null,null,null,null,"DefinedTermBase","DefinedTermBase"};
173 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
176 //DnaQuality in TissueSample
177 //TODO H2 / PostGreSQL / SQL Server
178 stepName
= "Add foreign key to dna quality";
179 tableName
= "SpecimenOrObservationBase";
180 newColumnName
= "dnaQuality_id";
181 boolean notNull
= false;
182 String referencedTable
= "DnaQuality";
183 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, newColumnName
, INCLUDE_AUDIT
, notNull
, referencedTable
);
186 //time scope for classifications
187 //TODO H2 / PostGreSQL / SQL Server
188 stepName
= "Add time scope (start) for classifications";
189 tableName
= "Classification";
190 newColumnName
= "timeperiod_start";
192 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, newColumnName
, length
, INCLUDE_AUDIT
);
195 //TODO H2 / PostGreSQL / SQL Server
196 stepName
= "Add time scope (end) for classifications";
197 tableName
= "Classification";
198 newColumnName
= "timeperiod_end";
200 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, newColumnName
, length
, INCLUDE_AUDIT
);
203 //TODO H2 / PostGreSQL / SQL Server
204 stepName
= "Add time scope (freetext) for classifications";
205 tableName
= "Classification";
206 newColumnName
= "timeperiod_freetext";
208 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, newColumnName
, length
, INCLUDE_AUDIT
);
211 //Classification_GeoScope
213 stepName
= "Create Classification_GeoScope table";
214 includeCdmBaseAttributes
= false;
215 tableName
= "Classification_GeoScope";
216 columnNames
= new String
[]{"Classification_id","geoScopes_id"};
217 columnTypes
= new String
[]{"int","int"};
218 referencedTables
= new String
[]{"Classification","DefinedTermBase"};
219 TableCreator creator
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
220 creator
.setPrimaryKeyParams("Classification_id,geoScopes_id", "REV,Classification_id,geoScopes_id");
221 stepList
.add(creator
);
223 //Classification_Description
225 stepName
= "Create Classification_Description table";
226 includeCdmBaseAttributes
= false;
227 tableName
= "Classification_Description";
228 columnNames
= new String
[]{"Classification_id","description_id","description_mapkey_id"};
229 columnTypes
= new String
[]{"int","int","int"};
230 referencedTables
= new String
[]{"Classification","LanguageString","DefinedTermBase"};
231 creator
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
232 creator
.setPrimaryKeyParams("Classification_id", "REV,Classification_id,description_id,description_mapkey_id");
233 stepList
.add(creator
);
235 //Primer.sequence type #4139
236 stepName
= "Add sequence string column to primer";
237 tableName
= "Primer";
238 newColumnName
= "sequence_string";
239 step
= ColumnAdder
.NewClobInstance(stepName
, tableName
, newColumnName
,
243 //Primer.sequence length
244 stepName
= "Add sequence length column to primer";
245 tableName
= "Primer";
246 newColumnName
= "sequence_length";
248 referencedTable
= null;
249 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, newColumnName
, INCLUDE_AUDIT
, null, notNull
);
252 //remove sequence_id column //we do not move data as we do not expect data available yet
253 stepName
= "Remove sequence_id column from primer";
254 tableName
= "Primer";
255 oldColumnName
= "sequence_id";
256 step
= ColumnRemover
.NewInstance(stepName
, tableName
, oldColumnName
, INCLUDE_AUDIT
);
259 //EntityValidationResult
261 stepName
= "Create EntityValidationResult table";
262 includeCdmBaseAttributes
= true;
263 tableName
= "EntityValidationResult";
264 columnNames
= new String
[]{"crudeventtype","userfriendlydescription","userfriendlytypename",
265 "validatedentityclass","validatedentityid","validatedentityuuid"};
266 columnTypes
= new String
[]{"string_255","string_255","string_255","string_255","int","string_36"};
267 referencedTables
= new String
[]{null,null,null,null,null,null};
268 creator
= TableCreator
.NewNonVersionableInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, ! INCLUDE_AUDIT
);
269 stepList
.add(creator
);
272 //EntityConstraintViolation
274 stepName
= "Create EntityConstraintViolation table";
275 includeCdmBaseAttributes
= true;
276 tableName
= "EntityConstraintViolation";
277 columnNames
= new String
[]{"invalidvalue","message","propertypath","severity","userfriendlyfieldname",
278 "validator","entityvalidationresult_id"};
279 columnTypes
= new String
[]{"string_255","string_255","string_255","string_255","string_255","string_255","int"};
280 referencedTables
= new String
[]{null,null,null,null,null,null,"EntityValidationResult"};
281 creator
= TableCreator
.NewNonVersionableInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, ! INCLUDE_AUDIT
);
282 stepList
.add(creator
);
290 private void addIdentifierTables(List
<ISchemaUpdaterStep
> stepList
) {
293 String stepName
= "Create Identifier table";
294 boolean includeCdmBaseAttributes
= true;
295 String tableName
= "Identifier";
296 String
[] columnNames
= new String
[]{"identifier","identifiedObj_type", "identifiedObj_id","type_id"};
297 String
[] columnTypes
= new String
[]{"string_800","string_255","int","int"};
298 String
[] referencedTables
= new String
[]{null,null,null,"DefinedTermBase"};
299 TableCreator step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
302 //AgentBase_Identifier
303 stepName
= "Create AgentBase_Identifier table";
304 includeCdmBaseAttributes
= false;
305 tableName
= "AgentBase_Identifier";
306 columnNames
= new String
[]{"AgentBase_id","identifiers_id","sortIndex"};
307 columnTypes
= new String
[]{"int","int","int"};
308 referencedTables
= new String
[]{"AgentBase","Identifier",null};
309 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
310 step
.setPrimaryKeyParams("AgentBase_id,identifiers_id", "REV,AgentBase_id,identifiers_id");
313 //Classification_Identifier
314 stepName
= "Create Classification_Identifier table";
315 includeCdmBaseAttributes
= false;
316 tableName
= "Classification_Identifier";
317 columnNames
= new String
[]{"Classification_id","identifiers_id","sortIndex"};
318 columnTypes
= new String
[]{"int","int","int"};
319 referencedTables
= new String
[]{"Classification","Identifier",null};
320 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
321 step
.setPrimaryKeyParams("Classification_id,identifiers_id", "REV,Classification_id,identifiers_id");
324 //Collection_Identifier
325 stepName
= "Create Collection_Identifier table";
326 includeCdmBaseAttributes
= false;
327 tableName
= "Collection_Identifier";
328 columnNames
= new String
[]{"Collection_id","identifiers_id","sortIndex"};
329 columnTypes
= new String
[]{"int","int","int"};
330 referencedTables
= new String
[]{"Collection","Identifier",null};
331 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
332 step
.setPrimaryKeyParams("Collection_id,identifiers_id", "REV,Collection_id,identifiers_id");
335 //DefinedTermBase_Identifier
336 stepName
= "Create DefinedTermBase_Identifier table";
337 includeCdmBaseAttributes
= false;
338 tableName
= "DefinedTermBase_Identifier";
339 columnNames
= new String
[]{"DefinedTermBase_id","identifiers_id","sortIndex"};
340 columnTypes
= new String
[]{"int","int","int"};
341 referencedTables
= new String
[]{"DefinedTermBase","Identifier",null};
342 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
343 step
.setPrimaryKeyParams("DefinedTermBase_id,identifiers_id", "REV,DefinedTermBase_id,identifiers_id");
346 //DescriptionBase_Identifier
347 stepName
= "Create DescriptionBase_Identifier table";
348 includeCdmBaseAttributes
= false;
349 tableName
= "DescriptionBase_Identifier";
350 columnNames
= new String
[]{"DescriptionBase_id","identifiers_id","sortIndex"};
351 columnTypes
= new String
[]{"int","int","int"};
352 referencedTables
= new String
[]{"DescriptionBase","Identifier",null};
353 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
354 step
.setPrimaryKeyParams("DescriptionBase_id,identifiers_id", "REV,DescriptionBase_id,identifiers_id");
357 //FeatureTree_Identifier
358 stepName
= "Create FeatureTree_Identifier table";
359 includeCdmBaseAttributes
= false;
360 tableName
= "FeatureTree_Identifier";
361 columnNames
= new String
[]{"FeatureTree_id","identifiers_id","sortIndex"};
362 columnTypes
= new String
[]{"int","int","int"};
363 referencedTables
= new String
[]{"FeatureTree","Identifier",null};
364 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
365 step
.setPrimaryKeyParams("FeatureTree_id,identifiers_id", "REV,FeatureTree_id,identifiers_id");
369 stepName
= "Create Media_Identifier table";
370 includeCdmBaseAttributes
= false;
371 tableName
= "Media_Identifier";
372 columnNames
= new String
[]{"Media_id","identifiers_id","sortIndex"};
373 columnTypes
= new String
[]{"int","int","int"};
374 referencedTables
= new String
[]{"Media","Identifier",null};
375 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
376 step
.setPrimaryKeyParams("Media_id,identifiers_id", "REV,Media_id,identifiers_id");
379 //PolytomousKey_Identifier
380 stepName
= "Create PolytomousKey_Identifier table";
381 includeCdmBaseAttributes
= false;
382 tableName
= "PolytomousKey_Identifier";
383 columnNames
= new String
[]{"PolytomousKey_id","identifiers_id","sortIndex"};
384 columnTypes
= new String
[]{"int","int","int"};
385 referencedTables
= new String
[]{"PolytomousKey","Identifier",null};
386 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
387 step
.setPrimaryKeyParams("PolytomousKey_id,identifiers_id", "REV,PolytomousKey_id,identifiers_id");
390 //Reference_Identifier
391 stepName
= "Create Reference_Identifier table";
392 includeCdmBaseAttributes
= false;
393 tableName
= "Reference_Identifier";
394 columnNames
= new String
[]{"Reference_id","identifiers_id","sortIndex"};
395 columnTypes
= new String
[]{"int","int","int"};
396 referencedTables
= new String
[]{"Reference","Identifier",null};
397 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
398 step
.setPrimaryKeyParams("Reference_id,identifiers_id", "REV,Reference_id,identifiers_id");
401 //SpecimenOrObservationBase_Identifier
402 stepName
= "Create SpecimenOrObservationBase_Identifier table";
403 includeCdmBaseAttributes
= false;
404 tableName
= "SpecimenOrObservationBase_Identifier";
405 columnNames
= new String
[]{"SpecimenOrObservationBase_id","identifiers_id","sortIndex"};
406 columnTypes
= new String
[]{"int","int","int"};
407 referencedTables
= new String
[]{"SpecimenOrObservationBase","Identifier",null};
408 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
409 step
.setPrimaryKeyParams("SpecimenOrObservationBase_id,identifiers_id", "REV,SpecimenOrObservationBase_id,identifiers_id");
412 //TaxonBase_Identifier
413 stepName
= "Create TaxonBase_Identifier table";
414 includeCdmBaseAttributes
= false;
415 tableName
= "TaxonBase_Identifier";
416 columnNames
= new String
[]{"TaxonBase_id","identifiers_id","sortIndex"};
417 columnTypes
= new String
[]{"int","int","int"};
418 referencedTables
= new String
[]{"TaxonBase","Identifier",null};
419 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
420 step
.setPrimaryKeyParams("TaxonBase_id,identifiers_id", "REV,TaxonBase_id,identifiers_id");
423 //TaxonNameBase_Identifier
424 stepName
= "Create TaxonNameBase_Identifier table";
425 includeCdmBaseAttributes
= false;
426 tableName
= "TaxonNameBase_Identifier";
427 columnNames
= new String
[]{"TaxonNameBase_id","identifiers_id","sortIndex"};
428 columnTypes
= new String
[]{"int","int","int"};
429 referencedTables
= new String
[]{"TaxonNameBase","Identifier",null};
430 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
431 step
.setPrimaryKeyParams("TaxonNameBase_id,identifiers_id", "REV,TaxonNameBase_id,identifiers_id");
434 //TermVocabulary_Identifier
435 stepName
= "Create TermVocabulary_Identifier table";
436 includeCdmBaseAttributes
= false;
437 tableName
= "TermVocabulary_Identifier";
438 columnNames
= new String
[]{"TermVocabulary_id","identifiers_id","sortIndex"};
439 columnTypes
= new String
[]{"int","int","int"};
440 referencedTables
= new String
[]{"TermVocabulary","Identifier",null};
441 step
= TableCreator
.NewInstance(stepName
, tableName
, columnNames
, columnTypes
, referencedTables
, INCLUDE_AUDIT
, includeCdmBaseAttributes
);
442 step
.setPrimaryKeyParams("TermVocabulary_id,identifiers_id", "REV,TermVocabulary_id,identifiers_id");
448 public ISchemaUpdater
getNextUpdater() {
453 public ISchemaUpdater
getPreviousUpdater() {
454 return SchemaUpdater_33_331
.NewInstance();