Skip to content

Commit

Permalink
All tests pass except createTableByColumns
Browse files Browse the repository at this point in the history
  • Loading branch information
fil512 committed Oct 28, 2019
1 parent f8e15ea commit a123bfe
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public FlywayMigration(BaseTask theTask, FlywayMigrator theFlywayMigrator) {

@Override
public MigrationVersion getVersion() {
return MigrationVersion.fromVersion(myTask.getFlywayVersion());
String flywayVersion = myTask.getFlywayVersion();
return MigrationVersion.fromVersion(flywayVersion);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import ca.uhn.fhir.jpa.migrate.JdbcUtils;
import ca.uhn.fhir.util.VersionEnum;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -44,8 +45,8 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
private String myExecuteOnlyIfTableExists;
private List<TableAndColumn> myConditionalOnExistenceOf = new ArrayList<>();

public ArbitrarySqlTask(String theRelease, String theVersion, String theTableName, String theDescription) {
super(theRelease, theVersion);
public ArbitrarySqlTask(VersionEnum theRelease, String theVersion, String theTableName, String theDescription) {
super(theRelease.toString(), theVersion);
myTableName = theTableName;
myDescription = theDescription;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ public JdbcTemplate newJdbcTemnplate() {
public abstract void execute() throws SQLException;

public String getFlywayVersion() {
return myRelease + "." + myVersion;
String retval = "";
String releasePart = myRelease;
if (releasePart.startsWith("V")) {
releasePart = releasePart.substring(1);
}
return releasePart + "." + myVersion;
}

public static class ExecutedStatement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import ca.uhn.fhir.util.StopWatch;
import ca.uhn.fhir.util.VersionEnum;
import com.google.common.collect.ForwardingMap;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
Expand Down Expand Up @@ -53,8 +54,8 @@ public void setBatchSize(int theBatchSize) {
/**
* Constructor
*/
public CalculateHashesTask(String theRelease, String theVersion) {
super(theRelease, theVersion);
public CalculateHashesTask(VersionEnum theRelease, String theVersion) {
super(theRelease.toString(), theVersion);
}

@Override
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,20 @@ public void addSql(@Language("SQL") String theSql) {
}

public class BuilderAddTableByColumns extends BuilderWithTableName implements IAcceptsTasks {
private final String myVersion;
private final AddTableByColumnTask myTask;

public BuilderAddTableByColumns(String theRelease, String theVersion, IAcceptsTasks theSink, String theTableName, String thePkColumnName) {
super(theRelease, theSink, theTableName);
myVersion = theVersion;
myTask = new AddTableByColumnTask(myRelease, theVersion);
myTask.setTableName(theTableName);
myTask.setPkColumn(thePkColumnName);
theSink.addTask(myTask);
}

@Override
public BuilderWithTableName.BuilderAddColumnWithName addColumn(String theVersion, String theColumnName) {
return new BuilderWithTableName.BuilderAddColumnWithName(myRelease, theVersion, theColumnName, this);
public BuilderWithTableName.BuilderAddColumnWithName addColumn(String theColumnName) {
return new BuilderWithTableName.BuilderAddColumnWithName(myRelease, myVersion, theColumnName, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AddColumnTest extends BaseTest {
public void testColumnDoesntAlreadyExist() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");

AddColumnTask task = new AddColumnTask();
AddColumnTask task = new AddColumnTask("1", "1");
task.setTableName("SOMETABLE");
task.setColumnName("newcol");
task.setColumnType(AddColumnTask.ColumnTypeEnum.LONG);
Expand All @@ -31,7 +31,7 @@ public void testColumnDoesntAlreadyExist() throws SQLException {
public void testAddColumnInt() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");

AddColumnTask task = new AddColumnTask();
AddColumnTask task = new AddColumnTask("1", "1");
task.setTableName("SOMETABLE");
task.setColumnName("newcolint");
task.setColumnType(AddColumnTask.ColumnTypeEnum.INT);
Expand All @@ -48,7 +48,7 @@ public void testAddColumnInt() throws SQLException {
public void testColumnAlreadyExists() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), newcol bigint)");

AddColumnTask task = new AddColumnTask();
AddColumnTask task = new AddColumnTask("1", "1");
task.setTableName("SOMETABLE");
task.setColumnName("newcol");
task.setColumnType(AddColumnTask.ColumnTypeEnum.LONG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void testAddForeignKey() throws SQLException {
executeSql("create table FOREIGNTBL (PID bigint not null, HOMEREF bigint)");
assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "HOME", "FOREIGNTBL"), empty());

AddForeignKeyTask task = new AddForeignKeyTask();
AddForeignKeyTask task = new AddForeignKeyTask("1", "1");
task.setTableName("FOREIGNTBL");
task.setColumnName("HOMEREF");
task.setConstraintName("FK_HOME_FOREIGN");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static class MyMigrationTasks extends BaseMigrationTasks<VersionEnum> {

public MyMigrationTasks() {
Builder v = forVersion(VersionEnum.V3_5_0);
v.addIdGenerator("SEQ_FOO");
v.addIdGenerator("1", "SEQ_FOO");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void testUniqueConstraintAlreadyExists() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
executeSql("ALTER TABLE SOMETABLE ADD CONSTRAINT IDX_ANINDEX UNIQUE(TEXTCOL)");

AddIndexTask task = new AddIndexTask();
AddIndexTask task = new AddIndexTask("1", "1");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
task.setColumns("TEXTCOL");
Expand All @@ -38,7 +38,7 @@ public void testUniqueIndexAlreadyExists() throws SQLException {
executeSql("create unique index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)");
executeSql("create unique index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

AddIndexTask task = new AddIndexTask();
AddIndexTask task = new AddIndexTask("1", "1");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
task.setColumns("PID", "TEXTCOL");
Expand All @@ -59,7 +59,7 @@ public void testNonUniqueIndexAlreadyExists() throws SQLException {
executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)");
executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

AddIndexTask task = new AddIndexTask();
AddIndexTask task = new AddIndexTask("1", "1");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
task.setColumns("PID", "TEXTCOL");
Expand All @@ -79,7 +79,7 @@ public void testIndexDoesntAlreadyExist() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
executeSql("create unique index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

AddIndexTask task = new AddIndexTask();
AddIndexTask task = new AddIndexTask("1", "1");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
task.setColumns("PID", "TEXTCOL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ private static class MyMigrationTasks extends BaseMigrationTasks<VersionEnum> {
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.BuilderWithTableName targetTable = v.addTableByColumns("1", "TGT_TABLE", "PID");
targetTable.addColumn("1", "PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);

Builder.BuilderAddTableByColumns fooTable = v.addTableByColumns("FOO_TABLE", "PID");
Builder.BuilderAddTableByColumns fooTable = v.addTableByColumns("1", "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");
fooTable.addForeignKey("FK_REF").toColumn("COL_REF").references("1", "TGT_TABLE", "PID");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AddTableTest extends BaseTest {
@Test
public void testTableDoesntAlreadyExist() throws SQLException {

AddTableRawSqlTask task = new AddTableRawSqlTask();
AddTableRawSqlTask task = new AddTableRawSqlTask("1", "1");
task.setTableName("SOMETABLE");
task.addSql(DriverTypeEnum.H2_EMBEDDED, "create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
getMigrator().addTask(task);
Expand All @@ -29,7 +29,7 @@ public void testTableAlreadyExists() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
assertThat(JdbcUtils.getTableNames(getConnectionProperties()), containsInAnyOrder("SOMETABLE"));

AddTableRawSqlTask task = new AddTableRawSqlTask();
AddTableRawSqlTask task = new AddTableRawSqlTask("1", "1");
task.setTableName("SOMETABLE");
task.addSql(DriverTypeEnum.H2_EMBEDDED, "create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
getMigrator().addTask(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void test350MigrateSearchParams() {
executeSql("insert into HFJ_RES_PARAM_PRESENT (PID, SP_ID, SP_PRESENT, HASH_PRESENT) values (100, 1, true, null)");
executeSql("insert into HFJ_RES_PARAM_PRESENT (PID, SP_ID, SP_PRESENT, HASH_PRESENT) values (101, 2, true, null)");

ArbitrarySqlTask task = new ArbitrarySqlTask("HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes");
ArbitrarySqlTask task = new ArbitrarySqlTask(VersionEnum.V3_5_0, "1", "HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes");
task.setExecuteOnlyIfTableExists("hfj_search_parm");
task.setBatchSize(1);
String sql = "SELECT " +
Expand Down Expand Up @@ -56,7 +56,7 @@ public void test350MigrateSearchParams() {

@Test
public void testExecuteOnlyIfTableExists() {
ArbitrarySqlTask task = new ArbitrarySqlTask("HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes");
ArbitrarySqlTask task = new ArbitrarySqlTask(VersionEnum.V3_5_0, "1", "HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes");
task.setBatchSize(1);
String sql = "SELECT * FROM HFJ_SEARCH_PARM";
task.addQuery(sql, ArbitrarySqlTask.QueryModeEnum.BATCH_UNTIL_NO_MORE, t -> {
Expand All @@ -82,7 +82,7 @@ public void testUpdateTask() {
};
migrator
.forVersion(VersionEnum.V3_5_0)
.addTableRawSql("A")
.addTableRawSql("1", "A")
.addSql("delete from TEST_UPDATE_TASK where RES_TYPE = 'Patient'");

getMigrator().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0));
Expand All @@ -106,8 +106,8 @@ public void testArbitrarySql() {
};
migrator
.forVersion(VersionEnum.V3_5_0)
.executeRawSql(DriverTypeEnum.H2_EMBEDDED, "delete from TEST_UPDATE_TASK where RES_TYPE = 'Patient'")
.executeRawSql(DriverTypeEnum.H2_EMBEDDED, "delete from TEST_UPDATE_TASK where RES_TYPE = 'Encounter'");
.executeRawSql("1", DriverTypeEnum.H2_EMBEDDED, "delete from TEST_UPDATE_TASK where RES_TYPE = 'Patient'")
.executeRawSql("2", DriverTypeEnum.H2_EMBEDDED, "delete from TEST_UPDATE_TASK where RES_TYPE = 'Encounter'");

getMigrator().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0));
getMigrator().migrate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.util.VersionEnum;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

Expand All @@ -17,7 +18,7 @@ public void testCreateHashes() {
executeSql("insert into HFJ_SPIDX_TOKEN (SP_MISSING, SP_NAME, RES_ID, RES_TYPE, SP_UPDATED, SP_SYSTEM, SP_VALUE, SP_ID) values (false, 'identifier', 999, 'Patient', '2018-09-03 07:44:49.196', 'urn:oid:1.2.410.100110.10.41308301', '88888888', 1)");
executeSql("insert into HFJ_SPIDX_TOKEN (SP_MISSING, SP_NAME, RES_ID, RES_TYPE, SP_UPDATED, SP_SYSTEM, SP_VALUE, SP_ID) values (false, 'identifier', 999, 'Patient', '2018-09-03 07:44:49.196', 'urn:oid:1.2.410.100110.10.41308301', '99999999', 2)");

CalculateHashesTask task = new CalculateHashesTask();
CalculateHashesTask task = new CalculateHashesTask(VersionEnum.V3_5_0, "1");
task.setTableName("HFJ_SPIDX_TOKEN");
task.setColumnName("HASH_IDENTITY");
task.addCalculator("HASH_IDENTITY", t -> BaseResourceIndexedSearchParam.calculateHashIdentity(t.getResourceType(), t.getString("SP_NAME")));
Expand Down Expand Up @@ -64,7 +65,7 @@ public void testCreateHashesLargeNumber() {
});
assertEquals(777L, count.longValue());

CalculateHashesTask task = new CalculateHashesTask();
CalculateHashesTask task = new CalculateHashesTask(VersionEnum.V3_5_0, "1");
task.setTableName("HFJ_SPIDX_TOKEN");
task.setColumnName("HASH_IDENTITY");
task.addCalculator("HASH_IDENTITY", t -> BaseResourceIndexedSearchParam.calculateHashIdentity(t.getResourceType(), t.getString("SP_NAME")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DropColumnTest extends BaseTest {
public void testDropColumn() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");

DropColumnTask task = new DropColumnTask();
DropColumnTask task = new DropColumnTask("1", "1");
task.setTableName("SOMETABLE");
task.setColumnName("TEXTCOL");
getMigrator().addTask(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void testDropForeignKey() throws SQLException {

assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "PARENT", "CHILD"), hasSize(1));

DropForeignKeyTask task = new DropForeignKeyTask();
DropForeignKeyTask task = new DropForeignKeyTask("1", "1");
task.setTableName("CHILD");
task.setParentTableName("PARENT");
task.setConstraintName("FK_MOM");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static class MyMigrationTasks extends BaseMigrationTasks<VersionEnum> {

public MyMigrationTasks() {
Builder v = forVersion(VersionEnum.V3_5_0);
v.dropIdGenerator("SEQ_FOO");
v.dropIdGenerator("1", "SEQ_FOO");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void testIndexAlreadyExists() throws SQLException {
executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)");
executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

DropIndexTask task = new DropIndexTask();
DropIndexTask task = new DropIndexTask("1", "1");
task.setDescription("Drop an index");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
Expand All @@ -32,7 +32,7 @@ public void testIndexDoesntAlreadyExist() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

DropIndexTask task = new DropIndexTask();
DropIndexTask task = new DropIndexTask("1", "1");
task.setDescription("Drop an index");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
Expand All @@ -50,7 +50,7 @@ public void testConstraintAlreadyExists() throws SQLException {
executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)");
executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

DropIndexTask task = new DropIndexTask();
DropIndexTask task = new DropIndexTask("1", "1");
task.setDescription("Drop an index");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
Expand All @@ -66,7 +66,7 @@ public void testConstraintDoesntAlreadyExist() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

DropIndexTask task = new DropIndexTask();
DropIndexTask task = new DropIndexTask("1", "1");
task.setDescription("Drop an index");
task.setIndexName("IDX_ANINDEX");
task.setTableName("SOMETABLE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void testDropExistingTable() throws SQLException {
executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)");
executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)");

DropTableTask task = new DropTableTask();
DropTableTask task = new DropTableTask("1", "1");
task.setTableName("SOMETABLE");
getMigrator().addTask(task);

Expand All @@ -35,7 +35,7 @@ public void testDropTableWithForeignKey() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, REMOTEPID bigint not null, primary key (PID))");
executeSql("alter table SOMETABLE add constraint FK_MYFK foreign key (REMOTEPID) references FOREIGNTABLE;");

DropTableTask task = new DropTableTask();
DropTableTask task = new DropTableTask("1", "1");
task.setTableName("SOMETABLE");
getMigrator().addTask(task);

Expand All @@ -49,7 +49,7 @@ public void testDropTableWithForeignKey() throws SQLException {
@Test
public void testDropNonExistingTable() throws SQLException {

DropTableTask task = new DropTableTask();
DropTableTask task = new DropTableTask("1", "1");
task.setTableName("SOMETABLE");
getMigrator().addTask(task);

Expand Down
Loading

0 comments on commit a123bfe

Please sign in to comment.