From af508f12598831aa83b0aac776715cb3fdf64d6b Mon Sep 17 00:00:00 2001 From: "Rokke, Sten Ivar" Date: Thu, 10 Mar 2016 13:15:53 +0100 Subject: [PATCH 1/2] Fixed #1120, 3.x->4.0 migration, storage group setting, moved tests --- flyway-core/pom.xml | 2 +- .../dbsupport/db2zos/createMetaDataTable.sql | 30 +- .../dbsupport/db2zos/upgradeMetaDataTable.sql | 65 +- .../DB2zOSConcurrentMigrationMediumTest.java | 23 +- .../db2zos/DB2zOSMigrationMediumTest.java | 1118 +++++++++++++---- .../sql/SqlMigrationResolverSmallTest.java | 54 +- .../classpath/ClassPathScannerSmallTest.java | 35 +- .../core/migration/MigrationTestCase.java | 55 +- .../{V1.1__Alias.sql => V1_1__Alias.sql} | 23 +- .../db2zos/sql/comment/V1_1__Comment.sql | 50 + ..._CreateTable.sql => V1_1__CreateTable.sql} | 25 +- .../db2zos/sql/crud/V1_2__UpdateTable.sql | 25 + .../db2zos/sql/crud/V1_3__UpdateTable.sql | 27 + .../dbsupport/db2zos/sql/crud/V1__First.sql | 25 + .../V1_1__CreateTable.sql} | 18 +- .../db2zos/sql/default/V1_2__UpdateTable.sql | 25 + .../db2zos/sql/default/V1_3__UpdateTable.sql | 27 + .../db2zos/sql/failed/V1_1__Should_Fail.sql | 24 + .../db2zos/sql/future_failed/V1_1__First.sql | 24 + .../future_failed/V1_2__Populate_table.sql | 19 + .../sql/future_failed/V2_0__Add_table.sql | 24 + .../sql/future_failed/V3__Should_Fail.sql | 18 + .../sql/outoforder/V1_1_1__Late_arrivals.sql | 19 + .../db2zos/sql/quote/V1_2__TableNameQuote.sql | 39 + ...{V1.1__Routines.sql => V1_1__Routines.sql} | 1 + .../sql/semicolon/V1_1__Populate_table.sql | 29 + ...{V1.1__Sequence.sql => V1_1__Sequence.sql} | 15 +- .../sql/subdir/V1_2__Populate_table.sql | 19 + .../db2zos/sql/subdir/dir1/V1_1__First.sql | 24 + .../sql/subdir/dir2/V2_0__Add_foreign_key.sql | 24 + .../{V1.1__Trigger.sql => V1_1__Trigger.sql} | 24 +- .../type/{V1.1__Type.sql => V1_1__Type.sql} | 2 + .../sql/validate/CheckValidate1_1__First.sql | 25 + .../db2zos/sql/validate/V1_1__First.sql | 23 + .../view/{V1.1__View.sql => V1_1__View.sql} | 23 +- 35 files changed, 1579 insertions(+), 424 deletions(-) rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/alias/{V1.1__Alias.sql => V1_1__Alias.sql} (63%) create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/comment/V1_1__Comment.sql rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/{V1.1__CreateTable.sql => V1_1__CreateTable.sql} (65%) create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_2__UpdateTable.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_3__UpdateTable.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1__First.sql rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/{crud/V1.2__UpdateTable.sql => default/V1_1__CreateTable.sql} (64%) create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_2__UpdateTable.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_3__UpdateTable.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/failed/V1_1__Should_Fail.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_1__First.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_2__Populate_table.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V2_0__Add_table.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V3__Should_Fail.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/outoforder/V1_1_1__Late_arrivals.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/quote/V1_2__TableNameQuote.sql rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/routines/{V1.1__Routines.sql => V1_1__Routines.sql} (95%) create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/semicolon/V1_1__Populate_table.sql rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/sequence/{V1.1__Sequence.sql => V1_1__Sequence.sql} (72%) create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/V1_2__Populate_table.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir1/V1_1__First.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir2/V2_0__Add_foreign_key.sql rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/trigger/{V1.1__Trigger.sql => V1_1__Trigger.sql} (73%) rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/type/{V1.1__Type.sql => V1_1__Type.sql} (95%) create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/CheckValidate1_1__First.sql create mode 100644 flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/V1_1__First.sql rename flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/view/{V1.1__View.sql => V1_1__View.sql} (76%) diff --git a/flyway-core/pom.xml b/flyway-core/pom.xml index c144774702..c9dfa4a4e4 100644 --- a/flyway-core/pom.xml +++ b/flyway-core/pom.xml @@ -380,7 +380,7 @@ com.ibm.db2 db2jcc - 8.1 + 3.4.65 test diff --git a/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/createMetaDataTable.sql b/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/createMetaDataTable.sql index 49c90c9a0c..a6b90d89f0 100644 --- a/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/createMetaDataTable.sql +++ b/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/createMetaDataTable.sql @@ -14,21 +14,17 @@ -- limitations under the License. -- -set current sqlid = '${schema}'; +SET CURRENT SQLID = '${schema}'; -CREATE TABLESPACE SDBVERS +CREATE TABLESPACE SFLYWAY IN "${schema}" - USING STOGROUP SENSITIV PRIQTY -1 SECQTY -1 ERASE NO FREEPAGE 0 PCTFREE 10 DEFINE YES TRACKMOD YES - SEGSIZE 64 - BUFFERPOOL BP3 - LOCKSIZE PAGE - LOCKMAX SYSTEM - CLOSE YES - COMPRESS YES - CCSID UNICODE -; - - + SEGSIZE 4 + BUFFERPOOL BP0 + LOCKSIZE PAGE + LOCKMAX SYSTEM + CLOSE YES + COMPRESS YES + ; CREATE TABLE "${schema}"."${table}" ( "installed_rank" INT NOT NULL, @@ -43,12 +39,10 @@ CREATE TABLE "${schema}"."${table}" ( "success" SMALLINT NOT NULL, CONSTRAINT "${table}_s" CHECK ("success" in(0,1)) ) -IN "${schema}".SDBVERS - CCSID UNICODE -; +IN "${schema}".SFLYWAY; +CREATE UNIQUE INDEX "${schema}"."${table}_IR_IDX" ON "${schema}"."${table}" ("installed_rank"); ALTER TABLE "${schema}"."${table}" ADD CONSTRAINT "${table}_PK" PRIMARY KEY ("installed_rank"); CREATE INDEX "${schema}"."${table}_S_IDX" ON "${schema}"."${table}" ("success"); - - +ALTER TABLE "${schema}"."${table}" ADD CONSTRAINT "${table}_S" CHECK ("success" in(0,1)); diff --git a/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/upgradeMetaDataTable.sql b/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/upgradeMetaDataTable.sql index 50cf669463..aa3cfcfe72 100644 --- a/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/upgradeMetaDataTable.sql +++ b/flyway-core/src/main/resources/org/flywaydb/core/internal/dbsupport/db2zos/upgradeMetaDataTable.sql @@ -14,11 +14,62 @@ -- limitations under the License. -- -DROP INDEX "${schema}"."${table}_vr_idx"; -DROP INDEX "${schema}"."${table}_ir_idx"; -ALTER TABLE "${schema}"."${table}" DROP COLUMN "version_rank"; -ALTER TABLE "${schema}"."${table}" DROP CONSTRAINT "${table}_pk"; -ALTER TABLE "${schema}"."${table}" ALTER COLUMN "version" DROP NOT NULL; -call ADMIN_CMD('REORG TABLE "${schema}"."${table}"'); -ALTER TABLE "${schema}"."${table}" ADD CONSTRAINT "${table}_pk" PRIMARY KEY ("installed_rank"); +SET CURRENT SQLID = '${schema}'; + +CREATE TABLESPACE SFLYWAY + IN "${schema}" + SEGSIZE 4 + BUFFERPOOL BP0 + LOCKSIZE PAGE + LOCKMAX SYSTEM + CLOSE YES + COMPRESS YES + ; + + +CREATE TABLE "${schema}"."TMP_${table}" ( + "installed_rank" INT NOT NULL, + "version" VARCHAR(50), + "description" VARCHAR(200) NOT NULL, + "type" VARCHAR(20) NOT NULL, + "script" VARCHAR(1000) NOT NULL, + "checksum" INT, + "installed_by" VARCHAR(100) NOT NULL, + "installed_on" TIMESTAMP NOT NULL WITH DEFAULT, + "execution_time" INT NOT NULL, + "success" SMALLINT NOT NULL, + CONSTRAINT "${table}_S" CHECK ("success" in(0,1)) +) +IN "${schema}".SFLYWAY; + + +INSERT INTO "${schema}"."TMP_${table}"( +SELECT + "installed_rank", + "version", + "description", + "type", + "script", + "checksum", + "installed_by", + "installed_on", + "execution_time", + "success" +FROM "${schema}"."${table}"); + +--drop all the old things +DROP TABLE "${schema}"."${table}"; +DROP TABLESPACE "${schema}".SDBVERS; + +RENAME TABLE "${schema}"."TMP_${table}" TO "${table}"; + UPDATE "${schema}"."${table}" SET "type"='BASELINE' WHERE "type"='INIT'; + +CREATE UNIQUE INDEX "${schema}"."${table}_IR_IDX" ON "${schema}"."${table}" ("installed_rank"); +ALTER TABLE "${schema}"."${table}" ADD CONSTRAINT "${table}_PK" PRIMARY KEY ("installed_rank"); + +CREATE INDEX "${schema}"."${table}_S_IDX" ON "${schema}"."${table}" ("success"); + + + + diff --git a/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSConcurrentMigrationMediumTest.java b/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSConcurrentMigrationMediumTest.java index 6dc4cf02c0..32edb65424 100644 --- a/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSConcurrentMigrationMediumTest.java +++ b/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSConcurrentMigrationMediumTest.java @@ -15,23 +15,24 @@ */ package org.flywaydb.core.internal.dbsupport.db2zos; +import java.util.Properties; + +import javax.sql.DataSource; + import org.flywaydb.core.DbCategory; -import org.flywaydb.core.migration.ConcurrentMigrationTestCase; import org.flywaydb.core.internal.util.jdbc.DriverDataSource; +import org.flywaydb.core.migration.ConcurrentMigrationTestCase; import org.junit.experimental.categories.Category; -import javax.sql.DataSource; -import java.util.Properties; - @Category(DbCategory.DB2zOS.class) public class DB2zOSConcurrentMigrationMediumTest extends ConcurrentMigrationTestCase { - @Override - protected DataSource createDataSource(Properties customProperties) throws Exception { - String user = customProperties.getProperty("db2.user", "TESTADMS"); - String password = customProperties.getProperty("db2.password", "passord"); - String url = customProperties.getProperty("db2.url", "jdbc:db2://host:port/schemaname"); + @Override + protected DataSource createDataSource(Properties customProperties) throws Exception { + String user = customProperties.getProperty("db2.user", "AURINTS"); + String password = customProperties.getProperty("db2.password", "password"); + String url = customProperties.getProperty("db2.url", "jdbc:db2://host:port/schemaname"); - return new DriverDataSource(Thread.currentThread().getContextClassLoader(),null, url, user, password); - } + return new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, user, password); + } } diff --git a/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSMigrationMediumTest.java b/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSMigrationMediumTest.java index 58bd3bcf91..4b2f3cce1d 100644 --- a/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSMigrationMediumTest.java +++ b/flyway-core/src/test/java/org/flywaydb/core/internal/dbsupport/db2zos/DB2zOSMigrationMediumTest.java @@ -15,255 +15,929 @@ */ package org.flywaydb.core.internal.dbsupport.db2zos; -import org.flywaydb.core.DbCategory; -import org.flywaydb.core.api.MigrationVersion; -import org.flywaydb.core.internal.dbsupport.Schema; -import org.flywaydb.core.migration.MigrationTestCase; -import org.flywaydb.core.internal.util.jdbc.DriverDataSource; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import javax.sql.DataSource; import java.sql.SQLException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; -import static org.junit.Assert.assertEquals; +import javax.sql.DataSource; + +import org.flywaydb.core.DbCategory; +import org.flywaydb.core.api.FlywayException; +import org.flywaydb.core.api.MigrationInfo; +import org.flywaydb.core.api.MigrationState; +import org.flywaydb.core.api.MigrationType; +import org.flywaydb.core.api.MigrationVersion; +import org.flywaydb.core.api.resolver.ResolvedMigration; +import org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException; +import org.flywaydb.core.internal.dbsupport.JdbcTemplate; +import org.flywaydb.core.internal.dbsupport.Schema; +import org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver; +import org.flywaydb.core.internal.util.Location; +import org.flywaydb.core.internal.util.PlaceholderReplacer; +import org.flywaydb.core.internal.util.jdbc.DriverDataSource; +import org.flywaydb.core.internal.util.scanner.Scanner; +import org.flywaydb.core.migration.MigrationTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; @Category(DbCategory.DB2zOS.class) public class DB2zOSMigrationMediumTest extends MigrationTestCase { - private String query; - - @Override - protected void configureFlyway() { - super.configureFlyway(); - flyway.setTable("SCHEMA_VERSION"); - flyway.setSchemas("TESTADM"); - flyway.setBaselineOnMigrate(true); - try { - jdbcTemplate.update("SET CURRENT SQLID = 'TESTADM';"); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - - @Override - protected DataSource createDataSource(Properties customProperties) throws Exception { - String user = customProperties.getProperty("db2.user", "TESTADMS"); - String password = customProperties.getProperty("db2.password", "password"); - String url = customProperties.getProperty("db2.url", "jdbc:db2://host:port/schemaname"); - - return new DriverDataSource(Thread.currentThread().getContextClassLoader(),null, url, user, password); - } - - - - @Override - protected String getQuoteLocation() { - return "migration/quote"; - } - - @Test - public void init() throws Exception { - - query = "select count(*) from sysibm.systables where dbname = 'TESTADM'"; - - flyway.baseline(); - int countTablesAfterInit = jdbcTemplate.queryForInt(query); - assertEquals(1, countTablesAfterInit); - } - - @Test - public void migrateCRUD() throws Exception { - - query = "select count(*) from sysibm.systables where dbname = 'TESTADM'"; - - flyway.setLocations("migration/dbsupport/db2zos/sql/crud"); - - int countTablesBeforeMigration = jdbcTemplate.queryForInt(query); - assertEquals(0, countTablesBeforeMigration); - flyway.baseline(); - flyway.migrate(); - int countTablesAfterMigration = jdbcTemplate.queryForInt(query); - assertEquals(2, countTablesAfterMigration); - - MigrationVersion version = flyway.info().current().getVersion(); - assertEquals("1.2", version.toString()); - assertEquals("UpdateTable", flyway.info().current().getDescription()); - assertEquals("Nils", jdbcTemplate.queryForString("select firstname from TESTADM.PERSON where lastname = 'Nilsen'")); - - } - - @Test - public void sequence() throws Exception { - flyway.setLocations("migration/dbsupport/db2zos/sql/sequence"); - flyway.baseline(); - flyway.migrate(); - - MigrationVersion migrationVersion = flyway.info().current().getVersion(); - assertEquals("1.1", migrationVersion.toString()); - assertEquals("Sequence", flyway.info().current().getDescription()); - assertEquals(666, jdbcTemplate.queryForInt("SELECT NEXTVAL FOR TESTADM.BEAST_SEQ from sysibm.sysdummy1")); - } - - @Test - public void type() throws Exception { - flyway.setLocations("migration/dbsupport/db2zos/sql/type"); - flyway.baseline(); - flyway.migrate(); - } - - @Test - public void view() throws Exception { - flyway.setLocations("migration/dbsupport/db2zos/sql/view"); - flyway.baseline(); - flyway.migrate(); - } - - @Test - public void trigger() throws Exception { - flyway.setLocations("migration/dbsupport/db2zos/sql/trigger"); - flyway.baseline(); - flyway.migrate(); - } - - @Test - public void routines() throws Exception { - flyway.setLocations("migration/dbsupport/db2zos/sql/routines"); - flyway.baseline(); - flyway.migrate(); - } - - - @Test - public void alias() throws Exception { - flyway.setLocations("migration/dbsupport/db2zos/sql/alias"); - flyway.baseline(); - flyway.migrate(); - } - - - /** - * Override schema test. db2 on zOS does not support "Create schema" - * - * @throws Exception - */ - @Override - @Test(expected = UnsupportedOperationException.class) - public void setCurrentSchema() throws Exception { - Schema schema = dbSupport.getSchema("current_schema_test"); - try { - schema.create(); - - flyway.setSchemas("current_schema_test"); - flyway.clean(); - - flyway.setLocations("migration/current_schema"); - Map placeholders = new HashMap(); - placeholders.put("schema1", dbSupport.quote("current_schema_test")); - flyway.setPlaceholders(placeholders); - flyway.migrate(); - } finally { - schema.drop(); - } - } - - @Override - @Test(expected = UnsupportedOperationException.class) - public void migrateMultipleSchemas() throws Exception { - flyway.setSchemas("flyway_1", "flyway_2", "flyway_3"); - flyway.clean(); - - flyway.setLocations("migration/multi"); - Map placeholders = new HashMap(); - placeholders.put("schema1", dbSupport.quote("flyway_1")); - placeholders.put("schema2", dbSupport.quote("flyway_2")); - placeholders.put("schema3", dbSupport.quote("flyway_3")); - flyway.setPlaceholders(placeholders); - flyway.migrate(); - assertEquals("2.0", flyway.info().current().getVersion().toString()); - assertEquals("Add foreign key", flyway.info().current().getDescription()); - assertEquals(0, flyway.migrate()); - - assertEquals(4, flyway.info().applied().length); - assertEquals(2, jdbcTemplate.queryForInt("select count(*) from " + dbSupport.quote("flyway_1") + ".test_user1")); - assertEquals(2, jdbcTemplate.queryForInt("select count(*) from " + dbSupport.quote("flyway_2") + ".test_user2")); - assertEquals(2, jdbcTemplate.queryForInt("select count(*) from " + dbSupport.quote("flyway_3") + ".test_user3")); - - flyway.clean(); - } - - - @Test - public void nonEmptySchemaWithDisableInitCheck() throws Exception { - jdbcTemplate.execute("CREATE TABLE t1 (\n" + - " name VARCHAR(25) NOT NULL,\n" + - " PRIMARY KEY(name))"); - - flyway.setLocations(BASEDIR); - flyway.setBaselineVersionAsString("0_1"); - flyway.setBaselineOnMigrate(false); - flyway.baseline(); - flyway.migrate(); - } + private String query; + + @Override + protected void configureFlyway() { + super.configureFlyway(); + flyway.setTable("SCHEMA_VERSION"); + flyway.setSchemas("AURINT"); + flyway.setBaselineOnMigrate(true); + try { + jdbcTemplate.update("SET CURRENT SQLID = 'AURINT';"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + protected void assertChecksum(MigrationInfo migrationInfo) { + SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver( + dbSupport, new Scanner(Thread.currentThread().getContextClassLoader()), + new Location(getBasedir() + "/default"), + PlaceholderReplacer.NO_PLACEHOLDERS, + "UTF-8", + "V", "R", "__", ".sql"); + List migrations = sqlMigrationResolver.resolveMigrations(); + for (ResolvedMigration migration : migrations) { + if (migration.getVersion().toString().equals(migrationInfo.getVersion().toString())) { + assertEquals("Wrong checksum for " + migrationInfo.getScript(), migration.getChecksum(), migrationInfo.getChecksum()); + } + } + } + + @Override + protected DataSource createDataSource(Properties customProperties) throws Exception { + String user = customProperties.getProperty("db2.user", "AURINTS"); + String password = customProperties.getProperty("db2.password", "password"); + String url = customProperties.getProperty("db2.url", "jdbc:db2://host:port/schemaname"); + + return new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, user, password); + } + + @Override + protected void createFlyway3MetadataTable() throws Exception { + jdbcTemplate.execute("CREATE TABLESPACE " + "\"SDBVERS\"" + + " IN AURINT " + + " SEGSIZE 4 " + + " BUFFERPOOL BP0 " + + " LOCKSIZE PAGE " + + " LOCKMAX SYSTEM " + + " CLOSE YES " + + " COMPRESS YES;"); + jdbcTemplate.execute("CREATE TABLE \"SCHEMA_VERSION\" (\n" + + " \"version_rank\" INT NOT NULL,\n" + + " \"installed_rank\" INT NOT NULL,\n" + + " \"version\" VARCHAR(50) NOT NULL,\n" + + " \"description\" VARCHAR(200) NOT NULL,\n" + + " \"type\" VARCHAR(20) NOT NULL,\n" + + " \"script\" VARCHAR(1000) NOT NULL,\n" + + " \"checksum\" INT,\n" + + " \"installed_by\" VARCHAR(100) NOT NULL,\n" + + " \"installed_on\" TIMESTAMP NOT NULL WITH DEFAULT,\n" + + " \"execution_time\" INT NOT NULL,\n" + + " \"success\" SMALLINT NOT NULL,\n" + + " CONSTRAINT \"schema_version_s\" CHECK (\"success\" in(0,1))\n" + + ")\n" + + "IN AURINT.\"SDBVERS\";"); + } + + @Override + protected void createTestTable() throws SQLException { + jdbcTemplate.execute("CREATE TABLE t1 (\n" + + " name VARCHAR(25) NOT NULL,\n" + + " PRIMARY KEY(name)) IN AURINT.SPERS;"); + } + + protected String getAliasLocation() { + return "migration/dbsupport/db2zos/sql/alias"; + } + + @Override + protected String getBasedir() { + return "migration/dbsupport/db2zos/sql/"; + } + + @Override + protected String getCommentLocation() { + return "migration/dbsupport/db2zos/sql/comment"; + } + + @Override + protected String getFutureFailedLocation() { + return "migration/dbsupport/db2zos/sql/future_failed"; + } + + @Override + protected String getMigrationDir() { + return "migration/dbsupport/db2zos/sql/crud/"; + } + + @Override + protected String getQuoteLocation() { + return "migration/dbsupport/db2zos/sql/quote/"; + } + + protected String getRoutineLocation() { + return "migration/dbsupport/db2zos/sql/routines"; + } + + @Override + protected String getSemiColonLocation() { + return "migration/dbsupport/db2zos/sql/semicolon"; + } + + protected String getSequenceLocation() { + return "migration/dbsupport/db2zos/sql/sequence"; + } + + protected String getTriggerLocation() { + return "migration/dbsupport/db2zos/sql/trigger"; + } + + protected String getTypeLocation() { + return "migration/dbsupport/db2zos/sql/type"; + } + + @Override + protected String getValidateLocation() { + return "migration/dbsupport/db2zos/sql/validate/"; + } + + protected String getViewLocation() { + return "migration/dbsupport/db2zos/sql/view"; + } + + protected void insertIntoFlyway3MetadataTable(JdbcTemplate jdbcTemplate, int versionRank, int installedRank, String version, String description, String type, String script, Integer checksum, String installedBy, + int executionTime, boolean success) throws SQLException { + jdbcTemplate.execute("INSERT INTO AURINT" + "." + dbSupport.quote("SCHEMA_VERSION") + + " (" + dbSupport.quote("version_rank") + + "," + dbSupport.quote("installed_rank") + + "," + dbSupport.quote("version") + + "," + dbSupport.quote("description") + + "," + dbSupport.quote("type") + + "," + dbSupport.quote("script") + + "," + dbSupport.quote("checksum") + + "," + dbSupport.quote("installed_by") + + "," + dbSupport.quote("execution_time") + + "," + dbSupport.quote("success") + + ") VALUES (?,?,?,?,?,?,?,?,?,?)", + versionRank, installedRank, version, description, type, script, checksum, installedBy, executionTime, success); + } + + /** + * Override setUp to create DB2 table space. + * + * @throws Exception + */ + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + jdbcTemplate.execute("CREATE TABLESPACE SPERS " + + " IN AURINT " + + " SEGSIZE 4 " + + " BUFFERPOOL BP0 " + + " LOCKSIZE PAGE " + + " LOCKMAX SYSTEM " + + " CLOSE YES " + + " COMPRESS YES;"); + } + + /** + * Override tearDown to delete DB2 table space. + * + * @throws Exception + */ + @Override + @After + public void tearDown() throws Exception { + try { + jdbcTemplate.execute("DROP TABLESPACE AURINT.SPERS\n"); + } catch (SQLException e) { + if (!e.getMessage().contains("-204")) { + fail(); + } + } + super.tearDown(); + } + + @Test + public void alias() throws Exception { + flyway.setLocations(getAliasLocation()); + flyway.baseline(); + flyway.migrate(); + } /** - * Check validation with INIT row. + * Override checkValidationWithInitRow. Setting schema and table space in SQL. + * + * @throws Exception */ @Override @Test public void checkValidationWithInitRow() throws Exception { - flyway.setLocations(BASEDIR); + flyway.setLocations(getMigrationDir()); flyway.setTarget(MigrationVersion.fromVersion("1.1")); + flyway.baseline(); flyway.migrate(); assertEquals("1.1", flyway.info().current().getVersion().toString()); - jdbcTemplate.update("DROP TABLE " + dbSupport.quote(flyway.getTable())); - jdbcTemplate.update("DROP TABLESPACE " + dbSupport.quote(flyway.getSchemas()) + ".SDBVERS"); + jdbcTemplate.update("DROP TABLESPACE AURINT.SFLYWAY\n"); flyway.setBaselineVersionAsString("1.1"); flyway.setBaselineDescription("initial version 1.1"); flyway.baseline(); - flyway.setTarget(MigrationVersion.LATEST); + flyway.setTarget(MigrationVersion.fromVersion("1.3")); + flyway.migrate(); + assertEquals("1.3", flyway.info().current().getVersion().toString()); + flyway.validate(); + } + + /** + * Override comment. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void comment() { + flyway.setLocations(getCommentLocation()); + flyway.baseline(); + assertEquals(1, flyway.migrate()); + } + + /** + * Override customTableName. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void customTableName() throws Exception { + flyway.setLocations(getMigrationDir()); + flyway.setTable("my_custom_table"); + flyway.baseline(); + flyway.migrate(); + int count = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM " + dbSupport.quote("my_custom_table")); + + // Same as 'migrate()', count is 5 when we have a schema creation marker + if (flyway.info().applied()[0].getType() == MigrationType.SCHEMA) { + assertEquals(5, count); + } else { + assertEquals(4, count); + } + } + + /** + * Override failedMigration. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void failedMigration() throws Exception { + String tableName = "before_the_error"; + + flyway.setLocations(getBasedir() + "/failed"); + Map placeholders = new HashMap(); + placeholders.put("tableName", dbSupport.quote(tableName)); + flyway.setPlaceholders(placeholders); + flyway.baseline(); + + try { + flyway.migrate(); + fail(); + } catch (FlywaySqlScriptException e) { + System.out.println(e.getMessage()); + // root cause of exception must be defined, and it should be FlywaySqlScriptException + assertNotNull(e.getCause()); + assertTrue(e.getCause() instanceof SQLException); + // and make sure the failed statement was properly recorded + assertEquals(23, e.getLineNumber()); + assertEquals("THIS IS NOT VALID SQL", e.getStatement()); + } + + MigrationInfo migration = flyway.info().current(); + assertEquals( + dbSupport.supportsDdlTransactions(), + !dbSupport.getSchema(dbSupport.getCurrentSchemaName()).getTable(tableName).exists()); + if (dbSupport.supportsDdlTransactions()) { + assertTrue(migration.getType().toString() == "BASELINE"); + } else { + MigrationVersion version = migration.getVersion(); + assertEquals("1", version.toString()); + assertEquals("Should Fail", migration.getDescription()); + assertEquals(MigrationState.FAILED, migration.getState()); + + // With schema markers, we'll have 2 applied + if (flyway.info().applied()[0].getType() == MigrationType.SCHEMA) { + assertEquals(2, flyway.info().applied().length); + } else { + assertEquals(1, flyway.info().applied().length); + } + + } + } + + /** + * Override futureFailedMigration. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void futureFailedMigration() throws Exception { + flyway.setValidateOnMigrate(false); + flyway.setLocations(getFutureFailedLocation()); + + try { + flyway.baseline(); + flyway.migrate(); + fail(); + } catch (FlywayException e) { + // Expected + } + + flyway.setIgnoreFutureMigrations(false); + flyway.setLocations(getMigrationDir()); + if (dbSupport.supportsDdlTransactions()) { + flyway.migrate(); + } else { + try { + flyway.migrate(); + fail(); + } catch (FlywayException e) { + // Expected + } + } + } + + /** + * Override futureFailedMigrationIgnore. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void futureFailedMigrationIgnore() throws Exception { + flyway.setValidateOnMigrate(false); + flyway.setLocations(getFutureFailedLocation()); + + try { + flyway.baseline(); + flyway.migrate(); + fail(); + } catch (FlywayException e) { + // Expected + } + + flyway.setIgnoreFailedFutureMigration(true); + flyway.setLocations(getMigrationDir()); + flyway.migrate(); + } + + /** + * Override futureFailedMigrationIgnoreAvailableMigrations. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void futureFailedMigrationIgnoreAvailableMigrations() throws Exception { + flyway.setValidateOnMigrate(false); + flyway.setLocations(getFutureFailedLocation()); + flyway.baseline(); + + try { + flyway.migrate(); + fail(); + } catch (FlywayException e) { + // Expected + } + + flyway.setIgnoreFailedFutureMigration(true); + try { + flyway.migrate(); + fail(); + } catch (FlywayException e) { + if (dbSupport.supportsDdlTransactions()) { + assertTrue(e.getMessage().contains("THIS IS NOT VALID SQL")); + } else { + assertTrue(e.getMessage().contains("contains a failed migration")); + } + } + } + + @Test + public void init() throws Exception { + query = "SELECT COUNT(*) FROM sysibm.systables WHERE dbname = 'AURINT'"; + + flyway.baseline(); + int countTablesAfterInit = jdbcTemplate.queryForInt(query); + assertEquals(1, countTablesAfterInit); + } + + /** + * Override isSchemaEmpty. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void isSchemaEmpty() throws Exception { + Schema schema = dbSupport.getSchema("AURINT"); + + assertTrue(schema.empty()); + + flyway.setLocations(getMigrationDir()); + flyway.baseline(); + flyway.migrate(); + + assertFalse(schema.empty()); + + flyway.clean(); + + assertTrue(schema.empty()); + } + + /** + * Override migrate. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void migrate() throws Exception { + flyway.setLocations(getBasedir() + "/default"); + flyway.baseline(); + flyway.migrate(); + MigrationVersion version = flyway.info().current().getVersion(); + assertEquals("1.3", version.toString()); + assertEquals(0, flyway.migrate()); + + // We should have 5 rows if we have a schema creation marker as the first entry, 4 otherwise + if (flyway.info().applied()[0].getType() == MigrationType.SCHEMA) { + assertEquals(5, flyway.info().applied().length); + } else { + assertEquals(4, flyway.info().applied().length); + } + + for (MigrationInfo migrationInfo : flyway.info().applied()) { + if (migrationInfo.getType().toString() != "BASELINE") { + assertChecksum(migrationInfo); + } + } + + assertEquals(4, jdbcTemplate.queryForInt("SELECT COUNT(*) FROM person")); + } + + @Test + public void migrateCRUD() throws Exception { + + query = "SELECT COUNT(*) FROM sysibm.systables WHERE dbname = 'AURINT'"; + + flyway.setLocations(getMigrationDir()); + + int countTablesBeforeMigration = jdbcTemplate.queryForInt(query); + assertEquals(0, countTablesBeforeMigration); + flyway.baseline(); + flyway.migrate(); + int countTablesAfterMigration = jdbcTemplate.queryForInt(query); + assertEquals(2, countTablesAfterMigration); + + MigrationVersion version = flyway.info().current().getVersion(); + assertEquals("1.3", version.toString()); + assertEquals("UpdateTable", flyway.info().current().getDescription()); + assertEquals("Nils", jdbcTemplate.queryForString("SELECT firstname FROM AURINT.PERSON WHERE lastname = 'Nilsen'")); + + } + + /** + * Override migrateMultipleSchemas. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test(expected = UnsupportedOperationException.class) + public void migrateMultipleSchemas() throws Exception { + flyway.setSchemas("flyway_1", "flyway_2", "flyway_3"); + flyway.clean(); + + flyway.setLocations("migration/multi"); + Map placeholders = new HashMap(); + placeholders.put("schema1", dbSupport.quote("flyway_1")); + placeholders.put("schema2", dbSupport.quote("flyway_2")); + placeholders.put("schema3", dbSupport.quote("flyway_3")); + flyway.setPlaceholders(placeholders); + flyway.migrate(); + assertEquals("2.0", flyway.info().current().getVersion().toString()); + assertEquals("Add foreign key", flyway.info().current().getDescription()); + assertEquals(0, flyway.migrate()); + + assertEquals(4, flyway.info().applied().length); + assertEquals(2, jdbcTemplate.queryForInt("SELECT COUNT(*) FROM " + dbSupport.quote("flyway_1") + ".test_user1")); + assertEquals(2, jdbcTemplate.queryForInt("SELECT COUNT(*) FROM " + dbSupport.quote("flyway_2") + ".test_user2")); + assertEquals(2, jdbcTemplate.queryForInt("SELECT COUNT(*) FROM " + dbSupport.quote("flyway_3") + ".test_user3")); + + flyway.clean(); + } + + /** + * Override nonEmptySchemaWithDisableInitCheck. createTestTable change. + * + * @throws Exception + */ + @Test + public void nonEmptySchemaWithDisableInitCheck() throws Exception { + createTestTable(); + + flyway.setLocations(getMigrationDir()); + flyway.setBaselineVersionAsString("0_1"); + flyway.setBaselineOnMigrate(false); + flyway.baseline(); + flyway.migrate(); + } + + /** + * Override nonEmptySchemaWithInit. createTestTable change. + * + * @throws Exception + */ + @Override + @Test + public void nonEmptySchemaWithInit() throws Exception { + createTestTable(); + + flyway.setLocations(getMigrationDir()); + flyway.setBaselineVersionAsString("0"); + flyway.baseline(); + flyway.migrate(); + } + + /** + * Override nonEmptySchemaWithInitOnMigrate. createTestTable change. + * + * @throws Exception + */ + @Override + @Test + public void nonEmptySchemaWithInitOnMigrate() throws Exception { + createTestTable(); + + flyway.setLocations(getMigrationDir()); + flyway.setBaselineVersionAsString("0"); + flyway.setBaselineOnMigrate(true); + flyway.migrate(); + MigrationInfo[] migrationInfos = flyway.info().all(); + + assertEquals(5, migrationInfos.length); + + assertEquals(MigrationType.BASELINE, migrationInfos[0].getType()); + assertEquals("0", migrationInfos[0].getVersion().toString()); + + assertEquals("1.3", flyway.info().current().getVersion().toString()); + } + + /** + * Override nonEmptySchemaWithInitOnMigrateHighVersion. createTestTable change. + * + * @throws Exception + */ + @Override + @Test + public void nonEmptySchemaWithInitOnMigrateHighVersion() throws Exception { + createTestTable(); + + flyway.setLocations(getMigrationDir()); + flyway.setBaselineOnMigrate(true); + flyway.setBaselineVersion(MigrationVersion.fromVersion("99")); + flyway.migrate(); + MigrationInfo[] migrationInfos = flyway.info().all(); + + assertEquals(5, migrationInfos.length); + + assertEquals(MigrationType.SQL, migrationInfos[0].getType()); + assertEquals("1", migrationInfos[0].getVersion().toString()); + assertEquals(MigrationState.BELOW_BASELINE, migrationInfos[0].getState()); + + MigrationInfo migrationInfo = flyway.info().current(); + assertEquals(MigrationType.BASELINE, migrationInfo.getType()); + assertEquals("99", migrationInfo.getVersion().toString()); + } + + /** + * Override outOfOrderMultipleRankIncrease. Setting schema and table space in SQL. + * + */ + @Override + @Test + public void outOfOrderMultipleRankIncrease() { + flyway.setLocations(getMigrationDir()); + flyway.baseline(); + flyway.migrate(); + + flyway.setLocations(getMigrationDir(), getBasedir() + "/outoforder"); + flyway.setOutOfOrder(true); + flyway.migrate(); + + MigrationInfo[] all = flyway.info().all(); + assertEquals(org.flywaydb.core.api.MigrationState.OUT_OF_ORDER, all[all.length - 1].getState()); + } + + /** + * Override quote. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void quote() throws Exception { + flyway.setLocations(getQuoteLocation()); + flyway.baseline(); flyway.migrate(); + assertEquals("0", + jdbcTemplate.queryForString("SELECT COUNT(name) FROM " + dbSupport.quote(flyway.getSchemas()[0], "table"))); + } + + /** + * Override quotesAroundTableName. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void quotesAroundTableName() { + flyway.setLocations(getQuoteLocation()); + flyway.baseline(); + flyway.migrate(); + } + + /** + * Override repair. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void repair() throws Exception { + flyway.setLocations(getFutureFailedLocation()); + assertEquals(4, flyway.info().all().length); + + try { + flyway.baseline(); + flyway.migrate(); + fail(); + } catch (FlywayException e) { + // Expected + } + + assertEquals("2.0", flyway.info().current().getVersion().toString()); + assertEquals(MigrationState.SUCCESS, flyway.info().current().getState()); + + flyway.repair(); assertEquals("2.0", flyway.info().current().getVersion().toString()); + assertEquals(MigrationState.SUCCESS, flyway.info().current().getState()); + } + + /** + * Override repairChecksum. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void repairChecksum() { + flyway.setLocations(getMigrationDir()); + flyway.baseline(); + Integer firstChecksum = flyway.info().pending()[0].getChecksum(); + Integer secondChecksum = flyway.info().pending()[1].getChecksum(); + + assertNotEquals(firstChecksum, secondChecksum); + + flyway.migrate(); + + if (flyway.info().applied()[0].getType() == MigrationType.SCHEMA) { + assertEquals(firstChecksum, flyway.info().applied()[2].getChecksum()); + } else { + assertEquals(firstChecksum, flyway.info().applied()[1].getChecksum()); + } + + flyway.setLocations(getCommentLocation()); + flyway.repair(); + + if (flyway.info().applied()[0].getType() == MigrationType.SCHEMA) { + assertEquals(secondChecksum, flyway.info().applied()[3].getChecksum()); + } else { + assertEquals(secondChecksum, flyway.info().applied()[2].getChecksum()); + } + } + + @Test + public void routines() throws Exception { + flyway.setLocations(getRoutineLocation()); + flyway.baseline(); + flyway.migrate(); + } + + @Override + @Test + public void schemaExists() throws SQLException { + assertTrue(dbSupport.getSchema("AURINT").exists()); + assertFalse(dbSupport.getSchema("InVaLidScHeMa").exists()); + } + + /** + * Override semicolonWithinStringLiteral. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void semicolonWithinStringLiteral() throws Exception { + flyway.setLocations(getSemiColonLocation()); + flyway.baseline(); + flyway.migrate(); + + assertEquals("1.1", flyway.info().current().getVersion().toString()); + assertEquals("Populate table", flyway.info().current().getDescription()); + + assertEquals("Semicolon+Linebreak;\nanother line", + jdbcTemplate.queryForString("SELECT lastname FROM person WHERE lastname like '%line'")); + } + + @Test + public void sequence() throws Exception { + flyway.setLocations(getSequenceLocation()); + flyway.baseline(); + flyway.migrate(); + + MigrationVersion migrationVersion = flyway.info().current().getVersion(); + assertEquals("1.1", migrationVersion.toString()); + assertEquals("Sequence", flyway.info().current().getDescription()); + assertEquals(666, jdbcTemplate.queryForInt("SELECT NEXTVAL FOR AURINT.beast_seq FROM sysibm.sysdummy1")); + } + + /** + * Override schema test. DB2 on zOS does not support "Create schema" + * + * @throws Exception + */ + @Override + @Test(expected = UnsupportedOperationException.class) + public void setCurrentSchema() throws Exception { + Schema schema = dbSupport.getSchema("current_schema_test"); + try { + schema.create(); + + flyway.setSchemas("current_schema_test"); + flyway.clean(); + + flyway.setLocations("migration/current_schema"); + Map placeholders = new HashMap(); + placeholders.put("schema1", dbSupport.quote("current_schema_test")); + flyway.setPlaceholders(placeholders); + flyway.migrate(); + } finally { + schema.drop(); + } + } + + /** + * Override subDir. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void subDir() { + flyway.setLocations(getBasedir() + "/subdir"); + flyway.baseline(); + assertEquals(3, flyway.migrate()); + } + + /** + * Override tableExists. Schema not same as user in DB2. + * + * @throws Exception + */ + @Override + @Test + public void tableExists() throws Exception { + flyway.baseline(); + assertTrue(dbSupport.getSchema("AURINT").getTable(flyway.getTable()).exists()); + assertTrue(dbSupport.getSchema(flyway.getSchemas()[0]).getTable(flyway.getTable()).exists()); + } + + /** + * Override target. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void target() throws Exception { + flyway.setLocations(getMigrationDir()); + + flyway.setTarget(MigrationVersion.fromVersion("1.2")); + flyway.baseline(); + flyway.migrate(); + assertEquals("1.2", flyway.info().current().getVersion().toString()); + assertEquals("UpdateTable", flyway.info().current().getDescription()); + + flyway.setTarget(MigrationVersion.fromVersion("1.0")); + flyway.migrate(); + assertEquals("1.2", flyway.info().current().getVersion().toString()); + assertEquals("UpdateTable", flyway.info().current().getDescription()); + + flyway.setTarget(MigrationVersion.LATEST); + flyway.migrate(); + assertEquals("1.3", flyway.info().current().getVersion().toString()); + assertEquals("UpdateTable", flyway.info().current().getDescription()); + } + + @Test + public void trigger() throws Exception { + flyway.setLocations(getTriggerLocation()); + flyway.baseline(); + flyway.migrate(); + } + + @Test + public void type() throws Exception { + flyway.setLocations(getTypeLocation()); + flyway.baseline(); + flyway.migrate(); + } + + /** + * Override upgradeMetadataTableTo40Format. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void upgradeMetadataTableTo40Format() throws Exception { + createFlyway3MetadataTable(); + jdbcTemplate.execute("CREATE TABLE test_user (\n" + + "id INT NOT NULL,\n" + + "name VARCHAR(25) NOT NULL, -- this is a valid ' comment\n" + + "PRIMARY KEY(name) /* and so is this ! */\n" + + ") IN AURINT.SPERS;"); + insertIntoFlyway3MetadataTable(jdbcTemplate, 1, 1, "0.1", "<< INIT >>", "INIT", "<< INIT >>", null, "flyway3", 0, true); + insertIntoFlyway3MetadataTable(jdbcTemplate, 2, 2, "1", "First", "SQL", "V1__First.sql", 1234, "flyway3", 15, true); + flyway.setLocations(getMigrationDir()); + assertEquals(3, flyway.migrate()); + flyway.validate(); + assertEquals(5, flyway.info().applied().length); + assertEquals(801496293, flyway.info().applied()[1].getChecksum().intValue()); + } + + /** + * Override validateClean. Setting schema and table space in SQL. + * + * @throws Exception + */ + @Override + @Test + public void validateClean() throws Exception { + flyway.setLocations(getValidateLocation()); + flyway.baseline(); + flyway.migrate(); + + assertEquals("1.1", flyway.info().current().getVersion().toString()); + + flyway.setValidateOnMigrate(true); + flyway.setCleanOnValidationError(true); + flyway.setSqlMigrationPrefix("CheckValidate"); + flyway.validate(); + assertEquals(0, jdbcTemplate.queryForInt("SELECT COUNT(*) FROM sysibm.systables WHERE owner='AURINT'")); } - @Override - protected void createFlyway3MetadataTable() throws Exception { - jdbcTemplate.execute("CREATE TABLESPACE SDBVERS\n" + - " USING STOGROUP SENSITIV PRIQTY -1 SECQTY -1 ERASE NO FREEPAGE 0 PCTFREE 10 DEFINE YES TRACKMOD YES\n" + - " SEGSIZE 64\n" + - " BUFFERPOOL BP3\n" + - " LOCKSIZE PAGE\n" + - " LOCKMAX SYSTEM\n" + - " CLOSE YES\n" + - " COMPRESS YES\n" + - " CCSID UNICODE"); - jdbcTemplate.execute("CREATE TABLE \"schema_version\" (\n" + - " \"version_rank\" INT NOT NULL,\n" + - " \"installed_rank\" INT NOT NULL,\n" + - " \"version\" VARCHAR(50) NOT NULL,\n" + - " \"description\" VARCHAR(200) NOT NULL,\n" + - " \"type\" VARCHAR(20) NOT NULL,\n" + - " \"script\" VARCHAR(1000) NOT NULL,\n" + - " \"checksum\" INT,\n" + - " \"installed_by\" VARCHAR(100) NOT NULL,\n" + - " \"installed_on\" TIMESTAMP NOT NULL WITH DEFAULT,\n" + - " \"execution_time\" INT NOT NULL,\n" + - " \"success\" SMALLINT NOT NULL,\n" + - " CONSTRAINT \"schema_version_s\" CHECK (\"success\" in(0,1))\n" + - ")\n" + - "IN SDBVERS\n" + - " CCSID UNICODE"); - jdbcTemplate.execute("CREATE UNIQUE INDEX \"schema_version_VPK_IDX\" \"schema_version\" (\"version\" ASC)"); - jdbcTemplate.execute("ALTER TABLE \"schema_version\" ADD CONSTRAINT \"schema_version_PK\" PRIMARY KEY (\"version\")"); - jdbcTemplate.execute("CREATE INDEX \"schema_version_VR_IDX\" ON \"schema_version\" (\"version_rank\")"); - jdbcTemplate.execute("CREATE INDEX \"schema_version_IR_IDX\" ON \"schema_version\" (\"installed_rank\")"); - jdbcTemplate.execute("CREATE INDEX \"schema_version_S_IDX\" ON \"schema_version\" (\"success\")"); - } + @Test + public void view() throws Exception { + flyway.setLocations(getViewLocation()); + flyway.baseline(); + flyway.migrate(); + } } diff --git a/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java b/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java index 0ff4ae9885..8f37b66bed 100644 --- a/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java +++ b/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java @@ -15,6 +15,14 @@ */ package org.flywaydb.core.internal.resolver.sql; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import org.flywaydb.core.api.resolver.ResolvedMigration; import org.flywaydb.core.internal.util.Location; import org.flywaydb.core.internal.util.PlaceholderReplacer; @@ -23,14 +31,6 @@ import org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource; import org.junit.Test; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - /** * Testcase for SqlMigration. */ @@ -40,9 +40,8 @@ public class SqlMigrationResolverSmallTest { @Test public void resolveMigrations() { - SqlMigrationResolver sqlMigrationResolver = - new SqlMigrationResolver(null, scanner, - new Location("migration/subdir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "V", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, + new Location("migration/subdir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "V", "R", "__", ".sql"); Collection migrations = sqlMigrationResolver.resolveMigrations(); assertEquals(3, migrations.size()); @@ -60,29 +59,26 @@ public void resolveMigrations() { @Test public void resolveMigrationsRoot() { - SqlMigrationResolver sqlMigrationResolver = - new SqlMigrationResolver(null, scanner, new Location(""), - PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "CheckValidate", "X", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location(""), + PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "CheckValidate", "X", "__", ".sql"); - //changed to 2 as new test cases are added for SybaseASE - assertEquals(2, sqlMigrationResolver.resolveMigrations().size()); + // changed to 3 as new test cases are added for SybaseASE and DB2 + assertEquals(3, sqlMigrationResolver.resolveMigrations().size()); } @Test public void resolveMigrationsNonExisting() { - SqlMigrationResolver sqlMigrationResolver = - new SqlMigrationResolver(null, scanner, - new Location("non/existing"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", - "CheckValidate", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, + new Location("non/existing"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", + "CheckValidate", "R", "__", ".sql"); sqlMigrationResolver.resolveMigrations(); } @Test public void extractScriptName() { - SqlMigrationResolver sqlMigrationResolver = - new SqlMigrationResolver(null, scanner, - new Location("db/migration"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, + new Location("db/migration"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); assertEquals("db_0__init.sql", sqlMigrationResolver.extractScriptName( new ClassPathResource("db/migration/db_0__init.sql", Thread.currentThread().getContextClassLoader()))); @@ -90,9 +86,8 @@ public void extractScriptName() { @Test public void extractScriptNameRootLocation() { - SqlMigrationResolver sqlMigrationResolver = - new SqlMigrationResolver(null, scanner, new Location(""), - PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location(""), + PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); assertEquals("db_0__init.sql", sqlMigrationResolver.extractScriptName( new ClassPathResource("db_0__init.sql", Thread.currentThread().getContextClassLoader()))); @@ -100,10 +95,9 @@ public void extractScriptNameRootLocation() { @Test public void extractScriptNameFileSystemPrefix() { - SqlMigrationResolver sqlMigrationResolver = - new SqlMigrationResolver(null, scanner, - new Location("filesystem:/some/dir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", - "V", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, + new Location("filesystem:/some/dir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", + "V", "R", "__", ".sql"); assertEquals("V3.171__patch.sql", sqlMigrationResolver.extractScriptName(new FileSystemResource("/some/dir/V3.171__patch.sql"))); } diff --git a/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java b/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java index e7df9ef9ca..01b5587dc2 100644 --- a/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java +++ b/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java @@ -15,6 +15,14 @@ */ package org.flywaydb.core.internal.util.scanner.classpath; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + import org.flywaydb.core.api.migration.jdbc.JdbcMigration; import org.flywaydb.core.internal.dbsupport.db2.DB2MigrationMediumTest; import org.flywaydb.core.internal.resolver.jdbc.dummy.V2__InterfaceBasedMigration; @@ -28,12 +36,6 @@ import org.mockito.MockSettings; import org.mockito.internal.creation.MockSettingsImpl; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import static org.junit.Assert.*; - /** * Tests for ClassPathScanner. */ @@ -56,30 +58,36 @@ public void scanForResources() throws Exception { public void scanForResourcesRoot() throws Exception { Resource[] resources = classPathScanner.scanForResources(new Location("classpath:"), "CheckValidate", ".sql"); - //changed to 2 as new test cases are added for SybaseASE - assertEquals(2, resources.length); + // changed to 3 as new test cases are added for SybaseASE and DB2 z/OS + assertEquals(3, resources.length); Set validPaths = new HashSet(); validPaths.add("migration/validate/CheckValidate1__First.sql"); validPaths.add("migration/dbsupport/sybaseASE/validate/CheckValidate1__First.sql"); + validPaths.add("migration/dbsupport/db2zos/sql/validate/CheckValidate1_1__First.sql"); assertEquals(true, validPaths.contains(resources[0].getLocation())); assertEquals(true, validPaths.contains(resources[1].getLocation())); + assertEquals(true, validPaths.contains(resources[2].getLocation())); } @Test public void scanForResourcesSomewhereInSubDir() throws Exception { Resource[] resources = classPathScanner.scanForResources(new Location("classpath:migration"), "CheckValidate", ".sql"); - - //changed to 2 as new test cases are added for SybaseASE - assertEquals(2, resources.length); + for (Resource resource : resources) { + System.out.println(resource.getLocation()); + } + // changed to 3 as new test cases are added for SybaseASE and DB2 z/OS + assertEquals(3, resources.length); Set validPaths = new HashSet(); - validPaths.add("migration/validate/CheckValidate1__First.sql"); validPaths.add("migration/dbsupport/sybaseASE/validate/CheckValidate1__First.sql"); + validPaths.add("migration/validate/CheckValidate1__First.sql"); + validPaths.add("migration/dbsupport/db2zos/sql/validate/CheckValidate1_1__First.sql"); assertEquals(true, validPaths.contains(resources[0].getLocation())); assertEquals(true, validPaths.contains(resources[1].getLocation())); + assertEquals(true, validPaths.contains(resources[2].getLocation())); } @Test @@ -109,8 +117,7 @@ public void scanForResourcesInvalidPath() throws Exception { @Test public void scanForResourcesSplitDirectory() throws Exception { - Resource[] resources = - classPathScanner.scanForResources(new Location("classpath:org/flywaydb/core/internal/dbsupport"), "create", ".sql"); + Resource[] resources = classPathScanner.scanForResources(new Location("classpath:org/flywaydb/core/internal/dbsupport"), "create", ".sql"); assertTrue(resources.length > 7); diff --git a/flyway-core/src/test/java/org/flywaydb/core/migration/MigrationTestCase.java b/flyway-core/src/test/java/org/flywaydb/core/migration/MigrationTestCase.java index 1668c6a854..6e2abf30e6 100644 --- a/flyway-core/src/test/java/org/flywaydb/core/migration/MigrationTestCase.java +++ b/flyway-core/src/test/java/org/flywaydb/core/migration/MigrationTestCase.java @@ -15,6 +15,25 @@ */ package org.flywaydb.core.migration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileInputStream; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.sql.DataSource; + import org.flywaydb.core.Flyway; import org.flywaydb.core.api.FlywayException; import org.flywaydb.core.api.MigrationInfo; @@ -38,22 +57,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.sql.DataSource; -import java.io.File; -import java.io.FileInputStream; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import static org.junit.Assert.*; - /** * Test to demonstrate the migration functionality. */ -@SuppressWarnings({"JavaDoc"}) +@SuppressWarnings({ "JavaDoc" }) public abstract class MigrationTestCase { private static final Logger LOG = LoggerFactory.getLogger(MigrationTestCase.class); @@ -95,7 +102,8 @@ protected void configureFlyway() { /** * Creates the datasource for this testcase based on these optional custom properties from the user home. * - * @param customProperties The optional custom properties. + * @param customProperties + * The optional custom properties. * @return The new datasource. */ protected abstract DataSource createDataSource(Properties customProperties) throws Exception; @@ -108,7 +116,8 @@ public void tearDown() throws Exception { protected void createFlyway3MetadataTable() throws Exception { } - private void insertIntoFlyway3MetadataTable(JdbcTemplate jdbcTemplate, int versionRank, int installedRank, String version, String description, String type, String script, Integer checksum, String installedBy, int executionTime, boolean success) throws SQLException { + private void insertIntoFlyway3MetadataTable(JdbcTemplate jdbcTemplate, int versionRank, int installedRank, String version, String description, String type, String script, Integer checksum, String installedBy, + int executionTime, boolean success) throws SQLException { jdbcTemplate.execute("INSERT INTO " + dbSupport.quote("schema_version") + " (" + dbSupport.quote("version_rank") + "," + dbSupport.quote("installed_rank") @@ -150,7 +159,7 @@ public void repair() throws Exception { flyway.migrate(); fail(); } catch (FlywayException e) { - //Expected + // Expected } LOG.info("\n" + MigrationInfoDumper.dumpToAsciiTable(flyway.info().all())); @@ -208,7 +217,6 @@ protected String getBasedir() { return BASEDIR; } - @Test public void migrate() throws Exception { flyway.setLocations(getBasedir()); @@ -268,9 +276,10 @@ public void customTableName() throws Exception { /** * Compares the DB checksum to the classpath checksum of this migration. * - * @param migrationInfo The migration to check. + * @param migrationInfo + * The migration to check. */ - private void assertChecksum(MigrationInfo migrationInfo) { + protected void assertChecksum(MigrationInfo migrationInfo) { SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver( dbSupport, new Scanner(Thread.currentThread().getContextClassLoader()), new Location(getBasedir()), @@ -375,7 +384,7 @@ public void futureFailedMigration() throws Exception { flyway.migrate(); fail(); } catch (FlywayException e) { - //Expected + // Expected } flyway.setIgnoreFutureMigrations(false); @@ -387,7 +396,7 @@ public void futureFailedMigration() throws Exception { flyway.migrate(); fail(); } catch (FlywayException e) { - //Expected + // Expected } } } @@ -401,7 +410,7 @@ public void futureFailedMigrationIgnore() throws Exception { flyway.migrate(); fail(); } catch (FlywayException e) { - //Expected + // Expected } flyway.setIgnoreFailedFutureMigration(true); @@ -418,7 +427,7 @@ public void futureFailedMigrationIgnoreAvailableMigrations() throws Exception { flyway.migrate(); fail(); } catch (FlywayException e) { - //Expected + // Expected } flyway.setIgnoreFailedFutureMigration(true); diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/alias/V1.1__Alias.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/alias/V1_1__Alias.sql similarity index 63% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/alias/V1.1__Alias.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/alias/V1_1__Alias.sql index b4c7218a4f..74d5dd4d32 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/alias/V1.1__Alias.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/alias/V1_1__Alias.sql @@ -14,30 +14,19 @@ -- limitations under the License. -- -CREATE TABLESPACE SPERS - IN TESTADM - USING STOGROUP SENSITIV PRIQTY -1 SECQTY -1 ERASE NO FREEPAGE 0 PCTFREE 10 DEFINE YES TRACKMOD YES - SEGSIZE 64 - BUFFERPOOL BP3 - LOCKSIZE PAGE - LOCKMAX SYSTEM - CLOSE YES - COMPRESS YES - CCSID UNICODE -; +SET CURRENT SQLID = 'AURINT'; CREATE TABLE EMPLOYEE ( "ID" integer not null, "NAME" varchar(100) ) - IN TESTADM.SPERS - CCSID UNICODE; + IN "AURINT".SPERS; --- Indekser og constraints +-- Indexes and constraints CREATE UNIQUE INDEX EMPLOYEE_pk_idx ON EMPLOYEE (id ASC); ALTER TABLE EMPLOYEE ADD CONSTRAINT EMPLOYEE_PK PRIMARY KEY (id); -INSERT INTO employee VALUES(1, 'Mark'); -INSERT INTO employee VALUES(2, 'Tommy'); +INSERT INTO EMPLOYEE VALUES(1, 'Mark'); +INSERT INTO EMPLOYEE VALUES(2, 'Tommy'); -CREATE ALIAS "POOR_SLAVE" FOR "EMPLOYEE"; \ No newline at end of file +CREATE ALIAS "POOR_SLAVE" FOR EMPLOYEE; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/comment/V1_1__Comment.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/comment/V1_1__Comment.sql new file mode 100644 index 0000000000..e807711ba6 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/comment/V1_1__Comment.sql @@ -0,0 +1,50 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +/* + First ' comment + */ + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE PERSON1 ( + name VARCHAR(25) NOT NULL, + -- second ' + PRIMARY KEY(name) +) IN "AURINT".SPERS; + +CREATE TABLE GROUP1 ( +/* + third ' + */ + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; + +-- 'fourth' +CREATE TABLE TABLE1 ( +-- ' fifth + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; + +CREATE TABLE TABLE2 ( +/*' + sixth + '*/ + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1.1__CreateTable.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_1__CreateTable.sql similarity index 65% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1.1__CreateTable.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_1__CreateTable.sql index a4ab2a36ea..43eb87eb5c 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1.1__CreateTable.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_1__CreateTable.sql @@ -14,33 +14,16 @@ -- limitations under the License. -- - - -CREATE TABLESPACE SPERS - IN TESTADM - USING STOGROUP SENSITIV PRIQTY -1 SECQTY -1 ERASE NO FREEPAGE 0 PCTFREE 10 DEFINE YES TRACKMOD YES - SEGSIZE 64 - BUFFERPOOL BP3 - LOCKSIZE PAGE - LOCKMAX SYSTEM - CLOSE YES - COMPRESS YES - CCSID UNICODE -; - +SET CURRENT SQLID = 'AURINT'; CREATE TABLE PERSON ( id INT NOT NULL, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL ) - IN TESTADM.SPERS - CCSID UNICODE -; + IN "AURINT".SPERS; --- Indekser og constraints +-- Indexes and constraints CREATE UNIQUE INDEX PERSON_pk_idx ON PERSON (id ASC); -ALTER TABLE PERSON ADD CONSTRAINT PERSON_PK PRIMARY KEY (id); - - +ALTER TABLE PERSON ADD CONSTRAINT PERSON_PK PRIMARY KEY (id); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_2__UpdateTable.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_2__UpdateTable.sql new file mode 100644 index 0000000000..a06df0fcb8 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_2__UpdateTable.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +INSERT INTO PERSON(id, firstname, lastname) values (1, 'Ole', 'Olsen'); +INSERT INTO PERSON(id, firstname, lastname) values (2, 'Per', 'Persen'); +INSERT INTO PERSON(id, firstname, lastname) values (3, 'Nils', 'Nilsen'); + +UPDATE PERSON set lastname = 'Hansen' Where id = 1; + +DELETE FROM PERSON WHERE lastname = 'Persen'; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_3__UpdateTable.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_3__UpdateTable.sql new file mode 100644 index 0000000000..a93445e55a --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1_3__UpdateTable.sql @@ -0,0 +1,27 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +INSERT INTO PERSON(id, firstname, lastname) values (4, 'Ole', 'Olsen'); +INSERT INTO PERSON(id, firstname, lastname) values (5, 'Per', 'Persen'); +INSERT INTO PERSON(id, firstname, lastname) values (6, 'Nils', 'Nilsen'); + +UPDATE PERSON set lastname = 'Hansen' Where id = 4; + +DELETE FROM PERSON WHERE lastname = 'Persen'; + + diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1__First.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1__First.sql new file mode 100644 index 0000000000..475c94597d --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1__First.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE test_user ( + id INT NOT NULL, + name VARCHAR(25) NOT NULL, -- this is a valid ' comment + PRIMARY KEY(name) /* and so is this ! */ +) IN "AURINT".SPERS; + +CREATE UNIQUE INDEX test_user_pk_idx ON test_user (name ASC); diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1.2__UpdateTable.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_1__CreateTable.sql similarity index 64% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1.2__UpdateTable.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_1__CreateTable.sql index beff32be5e..43eb87eb5c 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/crud/V1.2__UpdateTable.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_1__CreateTable.sql @@ -14,14 +14,16 @@ -- limitations under the License. -- - +SET CURRENT SQLID = 'AURINT'; - INSERT INTO PERSON(id, firstname, lastname) values (1, 'Ole', 'Olsen'); - INSERT INTO PERSON(id, firstname, lastname) values (2, 'Per', 'Persen'); - INSERT INTO PERSON(id, firstname, lastname) values (3, 'Nils', 'Nilsen'); - - UPDATE PERSON set lastname = 'Hansen' Where id = 1; - - DELETE FROM PERSON WHERE lastname = 'Persen'; +CREATE TABLE PERSON ( + id INT NOT NULL, + firstname VARCHAR(255) NOT NULL, + lastname VARCHAR(255) NOT NULL +) + IN "AURINT".SPERS; +-- Indexes and constraints +CREATE UNIQUE INDEX PERSON_pk_idx ON PERSON (id ASC); +ALTER TABLE PERSON ADD CONSTRAINT PERSON_PK PRIMARY KEY (id); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_2__UpdateTable.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_2__UpdateTable.sql new file mode 100644 index 0000000000..a06df0fcb8 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_2__UpdateTable.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +INSERT INTO PERSON(id, firstname, lastname) values (1, 'Ole', 'Olsen'); +INSERT INTO PERSON(id, firstname, lastname) values (2, 'Per', 'Persen'); +INSERT INTO PERSON(id, firstname, lastname) values (3, 'Nils', 'Nilsen'); + +UPDATE PERSON set lastname = 'Hansen' Where id = 1; + +DELETE FROM PERSON WHERE lastname = 'Persen'; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_3__UpdateTable.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_3__UpdateTable.sql new file mode 100644 index 0000000000..a93445e55a --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/default/V1_3__UpdateTable.sql @@ -0,0 +1,27 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +INSERT INTO PERSON(id, firstname, lastname) values (4, 'Ole', 'Olsen'); +INSERT INTO PERSON(id, firstname, lastname) values (5, 'Per', 'Persen'); +INSERT INTO PERSON(id, firstname, lastname) values (6, 'Nils', 'Nilsen'); + +UPDATE PERSON set lastname = 'Hansen' Where id = 4; + +DELETE FROM PERSON WHERE lastname = 'Persen'; + + diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/failed/V1_1__Should_Fail.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/failed/V1_1__Should_Fail.sql new file mode 100644 index 0000000000..4e88ac509d --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/failed/V1_1__Should_Fail.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE ${tableName} ( + id int +) IN "AURINT".SPERS; + +THIS IS NOT VALID SQL; +THIS MIGRATION SHOULD FAIL; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_1__First.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_1__First.sql new file mode 100644 index 0000000000..7f0f90a86b --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_1__First.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE PERSON ( + id INT NOT NULL, + firstname VARCHAR(255) NOT NULL, + lastname VARCHAR(255) NOT NULL +) + IN "AURINT".SPERS; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_2__Populate_table.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_2__Populate_table.sql new file mode 100644 index 0000000000..fc97546cd2 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V1_2__Populate_table.sql @@ -0,0 +1,19 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +INSERT INTO PERSON (id,firstname,lastname) VALUES (1, 'Mr.', 'T'); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V2_0__Add_table.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V2_0__Add_table.sql new file mode 100644 index 0000000000..9c9db12cd8 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V2_0__Add_table.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE COUPLE ( + id INT NOT NULL, + name1 VARCHAR(25) NOT NULL, + name2 VARCHAR(25) NOT NULL, + PRIMARY KEY(id) +) IN "AURINT".SPERS; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V3__Should_Fail.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V3__Should_Fail.sql new file mode 100644 index 0000000000..a8671f9a96 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/future_failed/V3__Should_Fail.sql @@ -0,0 +1,18 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +THIS IS NOT VALID SQL; +THIS MIGRATION SHOULD FAIL; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/outoforder/V1_1_1__Late_arrivals.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/outoforder/V1_1_1__Late_arrivals.sql new file mode 100644 index 0000000000..b74bb1cfd1 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/outoforder/V1_1_1__Late_arrivals.sql @@ -0,0 +1,19 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +INSERT INTO PERSON (id, firstname, lastname) VALUES (7, 'Dr.', 'Evil'); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/quote/V1_2__TableNameQuote.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/quote/V1_2__TableNameQuote.sql new file mode 100644 index 0000000000..6f31d592bf --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/quote/V1_2__TableNameQuote.sql @@ -0,0 +1,39 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE "user" ( + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; + +CREATE TABLE "group" ( + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; + +CREATE TABLE "table" ( + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; + +CREATE UNIQUE INDEX table_pk_idx ON "table" (name); + +CREATE TABLE "dol$lar" ( + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/routines/V1.1__Routines.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/routines/V1_1__Routines.sql similarity index 95% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/routines/V1.1__Routines.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/routines/V1_1__Routines.sql index 5aab22e76f..fe8437ad99 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/routines/V1.1__Routines.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/routines/V1_1__Routines.sql @@ -14,6 +14,7 @@ -- limitations under the License. -- +SET CURRENT SQLID = 'AURINT'; CREATE FUNCTION RandInt(core Int) RETURNS Int diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/semicolon/V1_1__Populate_table.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/semicolon/V1_1__Populate_table.sql new file mode 100644 index 0000000000..1275dcb4f4 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/semicolon/V1_1__Populate_table.sql @@ -0,0 +1,29 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE PERSON ( + id INT NOT NULL, + firstname VARCHAR(255) NOT NULL, + lastname VARCHAR(255) NOT NULL +) + IN "AURINT".SPERS; + +INSERT INTO PERSON (id,firstname,lastname) VALUES (1, 'Mr.', 'T'); +INSERT INTO PERSON (id,firstname,lastname) VALUES (2, 'Mr.', 'Semicolon;'); +INSERT INTO PERSON (id,firstname,lastname) VALUES (3, 'Mr.', 'Semicolon+Linebreak; +another line'); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/sequence/V1.1__Sequence.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/sequence/V1_1__Sequence.sql similarity index 72% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/sequence/V1.1__Sequence.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/sequence/V1_1__Sequence.sql index dd8ac2e036..8a11ca0f55 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/sequence/V1.1__Sequence.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/sequence/V1_1__Sequence.sql @@ -14,25 +14,14 @@ -- limitations under the License. -- -CREATE TABLESPACE SPERS - IN TESTADM - USING STOGROUP SENSITIV PRIQTY -1 SECQTY -1 ERASE NO FREEPAGE 0 PCTFREE 10 DEFINE YES TRACKMOD YES - SEGSIZE 64 - BUFFERPOOL BP3 - LOCKSIZE PAGE - LOCKMAX SYSTEM - CLOSE YES - COMPRESS YES - CCSID UNICODE -; +SET CURRENT SQLID = 'AURINT'; -- Identity sequence CREATE TABLE IDENTITY_CLEAN_TEST ( ID_ BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY, NAME_ VARCHAR(255) ) -IN TESTADM.SPERS - CCSID UNICODE; +IN "AURINT".SPERS; -- Regular sequence CREATE SEQUENCE BEAST_SEQ diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/V1_2__Populate_table.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/V1_2__Populate_table.sql new file mode 100644 index 0000000000..e212b34260 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/V1_2__Populate_table.sql @@ -0,0 +1,19 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +INSERT INTO test_user (name) VALUES ('Mr. T'); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir1/V1_1__First.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir1/V1_1__First.sql new file mode 100644 index 0000000000..0e10dbd3ae --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir1/V1_1__First.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE test_user ( + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +) IN "AURINT".SPERS; + +CREATE UNIQUE INDEX test_user_pk_idx ON test_user (name ASC); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir2/V2_0__Add_foreign_key.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir2/V2_0__Add_foreign_key.sql new file mode 100644 index 0000000000..4903677c21 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/subdir/dir2/V2_0__Add_foreign_key.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +CREATE TABLE couple ( + id INT NOT NULL, + name1 VARCHAR(25) NOT NULL, + name2 VARCHAR(25) NOT NULL, + PRIMARY KEY(id), + CONSTRAINT couple_user1_fk FOREIGN KEY (name1) REFERENCES test_user(name), + CONSTRAINT couple_user2_fk FOREIGN KEY (name2) REFERENCES test_user(name) +) IN "AURINT".SPERS; \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/trigger/V1.1__Trigger.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/trigger/V1_1__Trigger.sql similarity index 73% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/trigger/V1.1__Trigger.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/trigger/V1_1__Trigger.sql index 7c0fbffecc..fab0bf7d86 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/trigger/V1.1__Trigger.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/trigger/V1_1__Trigger.sql @@ -14,32 +14,19 @@ -- limitations under the License. -- - -CREATE TABLESPACE SPERS - IN TESTADM - USING STOGROUP SENSITIV PRIQTY -1 SECQTY -1 ERASE NO FREEPAGE 0 PCTFREE 10 DEFINE YES TRACKMOD YES - SEGSIZE 64 - BUFFERPOOL BP3 - LOCKSIZE PAGE - LOCKMAX SYSTEM - CLOSE YES - COMPRESS YES - CCSID UNICODE -; +SET CURRENT SQLID = 'AURINT'; CREATE TABLE EMPLOYEE ( id INT NOT NULL, name VARCHAR(25) NOT NULL ) -IN TESTADM.SPERS - CCSID UNICODE; +IN "AURINT".SPERS; CREATE TABLE COMPANY_STATS ( id INT NOT NULL, NBEMP INT ) -IN TESTADM.SPERS - CCSID UNICODE; +IN "AURINT".SPERS; CREATE UNIQUE INDEX COMPANY_STATS_pk_idx ON COMPANY_STATS (id ASC); ALTER TABLE COMPANY_STATS ADD CONSTRAINT COMPANY_STATS_PK PRIMARY KEY (id); @@ -50,7 +37,4 @@ ALTER TABLE EMPLOYEE ADD CONSTRAINT EMPLOYEE_PK PRIMARY KEY (id); CREATE TRIGGER NEW_HIRED AFTER INSERT ON EMPLOYEE FOR EACH ROW MODE DB2SQL - INSERT INTO COMPANY_STATS(id, NBEMP) VALUES (1, 1); - - - + INSERT INTO COMPANY_STATS(id, NBEMP) VALUES (1, 1); \ No newline at end of file diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/type/V1.1__Type.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/type/V1_1__Type.sql similarity index 95% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/type/V1.1__Type.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/type/V1_1__Type.sql index 6660bf34a7..25a32701c4 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/type/V1.1__Type.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/type/V1_1__Type.sql @@ -14,4 +14,6 @@ -- limitations under the License. -- +SET CURRENT SQLID = 'AURINT'; + CREATE TYPE TEMPERATURE AS DECIMAL(5,2); diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/CheckValidate1_1__First.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/CheckValidate1_1__First.sql new file mode 100644 index 0000000000..23f2885148 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/CheckValidate1_1__First.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- CHANGE IN COMMENT + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE PERSON ( + id INT NOT NULL, + firstname VARCHAR(255) NOT NULL, + lastname VARCHAR(255) NOT NULL +) IN "AURINT".SPERS; diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/V1_1__First.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/V1_1__First.sql new file mode 100644 index 0000000000..48cdf86711 --- /dev/null +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/validate/V1_1__First.sql @@ -0,0 +1,23 @@ +-- +-- Copyright 2010-2016 Boxfuse GmbH +-- +-- 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. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SET CURRENT SQLID = 'AURINT'; + +CREATE TABLE PERSON ( + id INT NOT NULL, + firstname VARCHAR(255) NOT NULL, + lastname VARCHAR(255) NOT NULL +) IN "AURINT".SPERS; diff --git a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/view/V1.1__View.sql b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/view/V1_1__View.sql similarity index 76% rename from flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/view/V1.1__View.sql rename to flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/view/V1_1__View.sql index 0f91750353..ce71b027a3 100644 --- a/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/view/V1.1__View.sql +++ b/flyway-core/src/test/resources/migration/dbsupport/db2zos/sql/view/V1_1__View.sql @@ -14,30 +14,16 @@ -- limitations under the License. -- -CREATE TABLESPACE SPERS - IN TESTADM - USING STOGROUP SENSITIV PRIQTY -1 SECQTY -1 ERASE NO FREEPAGE 0 PCTFREE 10 DEFINE YES TRACKMOD YES - SEGSIZE 64 - BUFFERPOOL BP3 - LOCKSIZE PAGE - LOCKMAX SYSTEM - CLOSE YES - COMPRESS YES - CCSID UNICODE -; - +SET CURRENT SQLID = 'AURINT'; CREATE TABLE PERSON ( id INT NOT NULL, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL ) - IN TESTADM.SPERS - CCSID UNICODE -; - + IN "AURINT".SPERS; --- Indekser og constraints +-- Indexes and constraints CREATE UNIQUE INDEX PERSON_pk_idx ON PERSON (id ASC); ALTER TABLE PERSON ADD CONSTRAINT PERSON_PK PRIMARY KEY (id); @@ -47,7 +33,6 @@ INSERT INTO PERSON(id, firstname, lastname) values (2, 'Per', 'Persen'); INSERT INTO PERSON(id, firstname, lastname) values (3, 'Nils', 'Nilsen'); -- View - CREATE VIEW PERSON_VIEW AS SELECT ID, FIRSTNAME - FROM PERSON \ No newline at end of file + FROM PERSON; \ No newline at end of file From b48dce738e969809336875992f3d98514c9eec28 Mon Sep 17 00:00:00 2001 From: "Rokke, Sten Ivar" Date: Thu, 10 Mar 2016 14:18:27 +0100 Subject: [PATCH 2/2] Format change and removed unecessary output --- .../sql/SqlMigrationResolverSmallTest.java | 34 +++++++++++-------- .../classpath/ClassPathScannerSmallTest.java | 4 +-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java b/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java index 8f37b66bed..a11c942200 100644 --- a/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java +++ b/flyway-core/src/test/java/org/flywaydb/core/internal/resolver/sql/SqlMigrationResolverSmallTest.java @@ -40,8 +40,9 @@ public class SqlMigrationResolverSmallTest { @Test public void resolveMigrations() { - SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, - new Location("migration/subdir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "V", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = + new SqlMigrationResolver(null, scanner, + new Location("migration/subdir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "V", "R", "__", ".sql"); Collection migrations = sqlMigrationResolver.resolveMigrations(); assertEquals(3, migrations.size()); @@ -59,8 +60,9 @@ public void resolveMigrations() { @Test public void resolveMigrationsRoot() { - SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location(""), - PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "CheckValidate", "X", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = + new SqlMigrationResolver(null, scanner, new Location(""), + PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "CheckValidate", "X", "__", ".sql"); // changed to 3 as new test cases are added for SybaseASE and DB2 assertEquals(3, sqlMigrationResolver.resolveMigrations().size()); @@ -68,17 +70,19 @@ public void resolveMigrationsRoot() { @Test public void resolveMigrationsNonExisting() { - SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, - new Location("non/existing"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", - "CheckValidate", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = + new SqlMigrationResolver(null, scanner, + new Location("non/existing"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", + "CheckValidate", "R", "__", ".sql"); sqlMigrationResolver.resolveMigrations(); } @Test public void extractScriptName() { - SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, - new Location("db/migration"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = + new SqlMigrationResolver(null, scanner, + new Location("db/migration"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); assertEquals("db_0__init.sql", sqlMigrationResolver.extractScriptName( new ClassPathResource("db/migration/db_0__init.sql", Thread.currentThread().getContextClassLoader()))); @@ -86,8 +90,9 @@ public void extractScriptName() { @Test public void extractScriptNameRootLocation() { - SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location(""), - PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = + new SqlMigrationResolver(null, scanner, new Location(""), + PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", "db_", "R", "__", ".sql"); assertEquals("db_0__init.sql", sqlMigrationResolver.extractScriptName( new ClassPathResource("db_0__init.sql", Thread.currentThread().getContextClassLoader()))); @@ -95,9 +100,10 @@ public void extractScriptNameRootLocation() { @Test public void extractScriptNameFileSystemPrefix() { - SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, - new Location("filesystem:/some/dir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", - "V", "R", "__", ".sql"); + SqlMigrationResolver sqlMigrationResolver = + new SqlMigrationResolver(null, scanner, + new Location("filesystem:/some/dir"), PlaceholderReplacer.NO_PLACEHOLDERS, "UTF-8", + "V", "R", "__", ".sql"); assertEquals("V3.171__patch.sql", sqlMigrationResolver.extractScriptName(new FileSystemResource("/some/dir/V3.171__patch.sql"))); } diff --git a/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java b/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java index 01b5587dc2..9f24058954 100644 --- a/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java +++ b/flyway-core/src/test/java/org/flywaydb/core/internal/util/scanner/classpath/ClassPathScannerSmallTest.java @@ -74,9 +74,7 @@ public void scanForResourcesRoot() throws Exception { @Test public void scanForResourcesSomewhereInSubDir() throws Exception { Resource[] resources = classPathScanner.scanForResources(new Location("classpath:migration"), "CheckValidate", ".sql"); - for (Resource resource : resources) { - System.out.println(resource.getLocation()); - } + // changed to 3 as new test cases are added for SybaseASE and DB2 z/OS assertEquals(3, resources.length);