Search in sources :

Example 1 with MockDatabaseConnection

use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementGenerationTypeOracleDatabase.

@Test
public void testAutoIncrementGenerationTypeOracleDatabase() {
    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);
            AutoIncrementConstraint autoIncrementConstraint = new AutoIncrementConstraint(COLUMN_NAME1);
            autoIncrementConstraint.setGenerationType("ALWAYS");
            // ignore when ALWAYS
            autoIncrementConstraint.setDefaultOnNull(true);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("SMALLINT{autoIncrement:true}", database), autoIncrementConstraint);
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME NUMBER(5) GENERATED ALWAYS AS IDENTITY)", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 2 with MockDatabaseConnection

use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByOracleDatabase.

@Test
public void testAutoIncrementStartWithIncrementByOracleDatabase() {
    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, BigInteger.TEN));
            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, INCREMENT BY 10))", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 3 with MockDatabaseConnection

use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementGenerationTypePostgresDatabase.

@Test
public void testAutoIncrementGenerationTypePostgresDatabase() {
    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);
            AutoIncrementConstraint constraint = new AutoIncrementConstraint(COLUMN_NAME1);
            constraint.setGenerationType("ALWAYS");
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), constraint);
            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 ALWAYS AS IDENTITY)", generatedSql[0].toSql());
        }
    }
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 4 with MockDatabaseConnection

use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.

the class CreateTableGeneratorTest method testGeneratedAlwaysPostgresDatabase.

@Test
public void testGeneratedAlwaysPostgresDatabase() 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("int", database), new ColumnConfig().setDefaultValue("GENERATED ALWAYS AS (rank_1 / 2) STORED").getDefaultValueObject());
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME INTEGER GENERATED ALWAYS AS (rank_1 / 2) STORED)", generatedSql[0].toSql());
        }
    }
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) ColumnConfig(liquibase.change.ColumnConfig) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 5 with MockDatabaseConnection

use of liquibase.database.MockDatabaseConnection in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementGenerationTypeDefaultOnNullOracleDatabase.

@Test
public void testAutoIncrementGenerationTypeDefaultOnNullOracleDatabase() {
    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);
            AutoIncrementConstraint autoIncrementConstraint = new AutoIncrementConstraint(COLUMN_NAME1);
            autoIncrementConstraint.setGenerationType("BY DEFAULT");
            autoIncrementConstraint.setDefaultOnNull(true);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("SMALLINT{autoIncrement:true}", database), autoIncrementConstraint);
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME NUMBER(5) GENERATED BY DEFAULT ON NULL AS IDENTITY)", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Aggregations

Database (liquibase.database.Database)10 MockDatabaseConnection (liquibase.database.MockDatabaseConnection)10 AbstractDb2Database (liquibase.database.core.AbstractDb2Database)10 DerbyDatabase (liquibase.database.core.DerbyDatabase)10 H2Database (liquibase.database.core.H2Database)10 HsqlDatabase (liquibase.database.core.HsqlDatabase)10 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)10 MySQLDatabase (liquibase.database.core.MySQLDatabase)10 OracleDatabase (liquibase.database.core.OracleDatabase)10 PostgresDatabase (liquibase.database.core.PostgresDatabase)10 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)10 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)10 SybaseDatabase (liquibase.database.core.SybaseDatabase)10 Sql (liquibase.sql.Sql)10 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)10 CreateTableStatement (liquibase.statement.core.CreateTableStatement)10 Test (org.junit.Test)10 ColumnConfig (liquibase.change.ColumnConfig)1