-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ergon/bugfix/enum-array-load-default-excep…
…tion fix loading of default values for enum arrays in postgres
- Loading branch information
Showing
3 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...st/src/test/java/ch/ergon/adam/integrationtest/postgresql/PostgreSqlAddSqlForNewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ch.ergon.adam.integrationtest.postgresql; | ||
|
||
import ch.ergon.adam.integrationtest.testcases.AddSqlForNewTest; | ||
|
||
public class PostgreSqlAddSqlForNewTest extends AddSqlForNewTest { | ||
public PostgreSqlAddSqlForNewTest() { | ||
super(new PostgreSqlTestDbUrlProvider()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
integration-test/src/test/java/ch/ergon/adam/integrationtest/testcases/AddSqlForNewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package ch.ergon.adam.integrationtest.testcases; | ||
|
||
import ch.ergon.adam.core.db.schema.DbEnum; | ||
import ch.ergon.adam.core.db.schema.Field; | ||
import ch.ergon.adam.core.db.schema.Schema; | ||
import ch.ergon.adam.core.db.schema.Table; | ||
import ch.ergon.adam.integrationtest.AbstractDbTestBase; | ||
import ch.ergon.adam.integrationtest.DummySink; | ||
import ch.ergon.adam.integrationtest.TestDbUrlProvider; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.ResultSet; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static ch.ergon.adam.core.db.schema.DataType.ENUM; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public abstract class AddSqlForNewTest extends AbstractDbTestBase { | ||
|
||
public AddSqlForNewTest(TestDbUrlProvider testDbUrlProvider) { | ||
super(testDbUrlProvider); | ||
} | ||
|
||
private static final String CREATE_ENUM_SQL = | ||
"create type custom_enum as enum ('val1', 'val2')"; | ||
|
||
private static final String CREATE_TABLE_SQL = | ||
"create table test_table (" + | ||
"col1 int" + | ||
")"; | ||
|
||
private static final String INSERT_DATA_SQL = | ||
"insert into test_table values (1)"; | ||
|
||
@Test | ||
public void testAddSqlForNewMigration() throws Exception { | ||
// Setup db | ||
getTargetDbConnection().createStatement().execute(CREATE_ENUM_SQL); | ||
getTargetDbConnection().createStatement().execute(CREATE_TABLE_SQL); | ||
getTargetDbConnection().createStatement().execute(INSERT_DATA_SQL); | ||
DummySink dummySink = targetToDummy(); | ||
Schema schema = dummySink.getTargetSchema(); | ||
|
||
// Add field | ||
Table table = schema.getTable("test_table"); | ||
List<Field> fields = new ArrayList<>(table.getFields()); | ||
Field newField = new Field("custom_type"); | ||
newField.setDataType(ENUM); | ||
newField.setDbEnum(new DbEnum("custom_enum")); | ||
newField.setArray(true); | ||
newField.setDefaultValue("'{val2}'"); | ||
newField.setSqlForNew("'{val1}'"); | ||
fields.add(newField); | ||
table.setFields(fields); | ||
migrateTargetWithSchema(schema); | ||
|
||
// Verify | ||
ResultSet result = getTargetDbConnection().createStatement().executeQuery("select * from test_table"); | ||
assertTrue(result.next()); | ||
assertThat(result.getString(2), is("{val1}")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters