Search in sources :

Example 41 with Database

use of liquibase.database.Database 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) {
            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());
        }
    }
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) DB2Database(liquibase.database.core.DB2Database) 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) HsqlDatabase(liquibase.database.core.HsqlDatabase) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 42 with Database

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithSybaseDatabase.

@Test
public void testAutoIncrementStartWithSybaseDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof SybaseDatabase) {
            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.valueOf(2), null));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            // start with not supported by Sybase
            assertEquals("CREATE TABLE [SCHEMA_NAME].[TABLE_NAME] ([COLUMN1_NAME] BIGINT IDENTITY NULL)", generatedSql[0].toSql());
        }
    }
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) SybaseDatabase(liquibase.database.core.SybaseDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) DB2Database(liquibase.database.core.DB2Database) 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) HsqlDatabase(liquibase.database.core.HsqlDatabase) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 43 with Database

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

the class CreateTableGeneratorTest method testWithColumnWithDefaultValue.

@Test
public void testWithColumnWithDefaultValue() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof OracleDatabase) {
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("java.sql.Types.TIMESTAMP", database), new ColumnConfig().setDefaultValue("null").getDefaultValueObject());
            if (shouldBeImplementation(database)) {
                assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME TIMESTAMP DEFAULT null)", this.generatorUnderTest.generateSql(statement, database, null)[0].toSql());
            }
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) ColumnConfig(liquibase.change.ColumnConfig) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) DB2Database(liquibase.database.core.DB2Database) 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) HsqlDatabase(liquibase.database.core.HsqlDatabase) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 44 with Database

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByH2Database.

@Test
public void testAutoIncrementStartWithIncrementByH2Database() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof H2Database) {
            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);
            assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT AUTO_INCREMENT (0, 10))", generatedSql[0].toSql());
        }
    }
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) DB2Database(liquibase.database.core.DB2Database) 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) HsqlDatabase(liquibase.database.core.HsqlDatabase) H2Database(liquibase.database.core.H2Database) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 45 with Database

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

the class CreateTableGeneratorTest method testAutoIncrementMSSQLDatabase.

@Test
public void testAutoIncrementMSSQLDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof MSSQLDatabase) {
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new ColumnConstraint[] { new AutoIncrementConstraint(COLUMN_NAME1), new NotNullConstraint(COLUMN_NAME1) });
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("Error on " + database, "CREATE TABLE [CATALOG_NAME].[SCHEMA_NAME].[TABLE_NAME] ([COLUMN1_NAME] [bigint] IDENTITY (1, 1) NOT NULL)", generatedSql[0].toSql());
        }
    }
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) DB2Database(liquibase.database.core.DB2Database) 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) HsqlDatabase(liquibase.database.core.HsqlDatabase) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) NotNullConstraint(liquibase.statement.NotNullConstraint) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Aggregations

Database (liquibase.database.Database)147 Test (org.junit.Test)74 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)50 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)43 Sql (liquibase.sql.Sql)42 DB2Database (liquibase.database.core.DB2Database)41 OracleDatabase (liquibase.database.core.OracleDatabase)39 PostgresDatabase (liquibase.database.core.PostgresDatabase)37 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)36 MySQLDatabase (liquibase.database.core.MySQLDatabase)35 DerbyDatabase (liquibase.database.core.DerbyDatabase)33 H2Database (liquibase.database.core.H2Database)33 HsqlDatabase (liquibase.database.core.HsqlDatabase)33 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)33 SybaseDatabase (liquibase.database.core.SybaseDatabase)33 CreateTableStatement (liquibase.statement.core.CreateTableStatement)33 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)30 DatabaseException (liquibase.exception.DatabaseException)25 AbstractJdbcDatabaseTest (liquibase.database.AbstractJdbcDatabaseTest)21 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)17