Search in sources :

Example 11 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementStartWithH2Database.

@Test
public void testAutoIncrementStartWithH2Database() 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, null));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT AUTO_INCREMENT (0))", 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 12 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class AddColumnGeneratorTest method isValid.

@Override
public void isValid() throws Exception {
    super.isValid();
    AddColumnStatement addPKColumn = new AddColumnStatement(null, null, TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, null, new PrimaryKeyConstraint("pk_name"));
    assertFalse(generatorUnderTest.validate(addPKColumn, new OracleDatabase(), new MockSqlGeneratorChain()).hasErrors());
    assertTrue(generatorUnderTest.validate(addPKColumn, new H2Database(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(addPKColumn, new DB2Database(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(addPKColumn, new DerbyDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(addPKColumn, new SQLiteDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a primary key column"));
    assertTrue(generatorUnderTest.validate(new AddColumnStatement(null, null, null, null, null, null, new AutoIncrementConstraint()), new MySQLDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a non-primary key identity column"));
    assertTrue(generatorUnderTest.validate(new AddColumnStatement(null, null, null, null, null, null, new AutoIncrementConstraint()), new MySQLDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("Cannot add a non-primary key identity column"));
    assertTrue(generatorUnderTest.validate(new AddColumnStatement(new AddColumnStatement(null, null, TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, null), new AddColumnStatement(null, null, "other_table", "other_column", COLUMN_TYPE, null)), new MySQLDatabase(), new MockSqlGeneratorChain()).getErrorMessages().contains("All columns must be targeted at the same table"));
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) DB2Database(liquibase.database.core.DB2Database) AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) H2Database(liquibase.database.core.H2Database) AddColumnStatement(liquibase.statement.core.AddColumnStatement) PrimaryKeyConstraint(liquibase.statement.PrimaryKeyConstraint) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain)

Example 13 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementH2Database.

@Test
public void testAutoIncrementH2Database() 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));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT AUTO_INCREMENT)", 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 14 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class SqlGeneratorFactoryTest method getGenerators.

@Test
public void getGenerators() {
    SortedSet<SqlGenerator> allGenerators = SqlGeneratorFactory.getInstance().getGenerators(new AddAutoIncrementStatement(null, null, "person", "name", "varchar(255)", null, null), new H2Database());
    assertNotNull(allGenerators);
    assertEquals(1, allGenerators.size());
}
Also used : AddAutoIncrementStatement(liquibase.statement.core.AddAutoIncrementStatement) H2Database(liquibase.database.core.H2Database) Test(org.junit.Test)

Aggregations

H2Database (liquibase.database.core.H2Database)14 Test (org.junit.Test)13 MySQLDatabase (liquibase.database.core.MySQLDatabase)7 OracleDatabase (liquibase.database.core.OracleDatabase)7 DB2Database (liquibase.database.core.DB2Database)5 DerbyDatabase (liquibase.database.core.DerbyDatabase)5 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)5 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)5 Database (liquibase.database.Database)4 HsqlDatabase (liquibase.database.core.HsqlDatabase)4 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)4 PostgresDatabase (liquibase.database.core.PostgresDatabase)4 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)4 SybaseDatabase (liquibase.database.core.SybaseDatabase)4 Sql (liquibase.sql.Sql)4 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)4 CreateTableStatement (liquibase.statement.core.CreateTableStatement)4 HashSet (java.util.HashSet)2 ContextExpression (liquibase.ContextExpression)2 Contexts (liquibase.Contexts)2