Make it easier to add tables with migrator tools
This commit is contained in:
parent
4a6345d7c4
commit
c4dd06ad0c
|
@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
|
|||
*/
|
||||
|
||||
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -36,6 +37,7 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
|||
private String myPkColumn;
|
||||
|
||||
public void addAddColumnTask(AddColumnTask theTask) {
|
||||
Validate.notNull(theTask);
|
||||
myAddColumnTasks.add(theTask);
|
||||
}
|
||||
|
||||
|
|
|
@ -353,7 +353,11 @@ public class BaseMigrationTasks<T extends Enum> {
|
|||
|
||||
@Override
|
||||
public void addTask(BaseTask<?> theTask) {
|
||||
myTask.addAddColumnTask((AddColumnTask) theTask);
|
||||
if (theTask instanceof AddColumnTask) {
|
||||
myTask.addAddColumnTask((AddColumnTask) theTask);
|
||||
} else {
|
||||
super.addTask(theTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,7 @@ public class AddTableByColumnTaskTest extends BaseTest {
|
|||
getMigrator().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0));
|
||||
getMigrator().migrate();
|
||||
|
||||
assertThat(JdbcUtils.getTableNames(getConnectionProperties()), containsInAnyOrder("FOO_TABLE"));
|
||||
|
||||
|
||||
assertThat(JdbcUtils.getTableNames(getConnectionProperties()), containsInAnyOrder("FOO_TABLE", "TGT_TABLE"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,9 +27,17 @@ public class AddTableByColumnTaskTest extends BaseTest {
|
|||
|
||||
public MyMigrationTasks() {
|
||||
Builder v = forVersion(VersionEnum.V3_5_0);
|
||||
|
||||
Builder.BuilderWithTableName targetTable = v.addTableByColumns("TGT_TABLE", "PID");
|
||||
targetTable.addColumn("PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
|
||||
|
||||
Builder.BuilderAddTableByColumns fooTable = v.addTableByColumns("FOO_TABLE", "PID");
|
||||
fooTable.addColumn("PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
|
||||
fooTable.addColumn("HELLO").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200);
|
||||
fooTable.addColumn("COL_REF").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
|
||||
fooTable.addIndex("IDX_HELLO").unique(true).withColumns("HELLO");
|
||||
fooTable.addForeignKey("FK_REF").toColumn("COL_REF").references("TGT_TABLE", "PID");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,4 @@ public class HapiFhirJpaMigrationTasksTest {
|
|||
new HapiFhirJpaMigrationTasks(Collections.emptySet());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue