use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementStartWithPostgresDatabase.
@Test
public void testAutoIncrementStartWithPostgresDatabase() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof PostgresDatabase) {
MockDatabaseConnection conn = new MockDatabaseConnection();
conn.setDatabaseMajorVersion(9);
database.setConnection(conn);
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.ZERO, null));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
// start with supported over generated sequence
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGSERIAL)", generatedSql[0].toSql());
conn.setDatabaseMajorVersion(10);
generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
}
}
}
use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementPostgresDatabase.
@Test
public void testAutoIncrementPostgresDatabase() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof PostgresDatabase) {
MockDatabaseConnection conn = new MockDatabaseConnection();
conn.setDatabaseMajorVersion(9);
database.setConnection(conn);
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGSERIAL)", generatedSql[0].toSql());
conn.setDatabaseMajorVersion(10);
generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY)", generatedSql[0].toSql());
}
}
}
use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementStartWithOracleDatabase.
@Test
public void testAutoIncrementStartWithOracleDatabase() {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof OracleDatabase) {
MockDatabaseConnection conn = new MockDatabaseConnection();
database.setConnection(conn);
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("SMALLINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.ZERO, null));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME NUMBER(5) GENERATED BY DEFAULT AS IDENTITY (START WITH 0))", generatedSql[0].toSql());
}
}
}
use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementOracleDatabase.
@Test
public void testAutoIncrementOracleDatabase() {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof OracleDatabase) {
MockDatabaseConnection conn = new MockDatabaseConnection();
database.setConnection(conn);
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("SMALLINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME NUMBER(5) GENERATED BY DEFAULT AS IDENTITY)", generatedSql[0].toSql());
}
}
}
use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByPostgresDatabase.
@Test
public void testAutoIncrementStartWithIncrementByPostgresDatabase() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof PostgresDatabase) {
MockDatabaseConnection conn = new MockDatabaseConnection();
conn.setDatabaseMajorVersion(9);
database.setConnection(conn);
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.ZERO, BigInteger.TEN));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
// start with and increment by supported over generated sequence
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGSERIAL)", generatedSql[0].toSql());
conn.setDatabaseMajorVersion(10);
generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0, INCREMENT BY 10))", generatedSql[0].toSql());
}
}
}
Aggregations