Search in sources :

Example 1 with DerbyDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementDerbyDatabase.

@Test
public void testAutoIncrementDerbyDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof DerbyDatabase) {
            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 CATALOG_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY)", generatedSql[0].toSql());
        }
    }
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) DerbyDatabase(liquibase.database.core.DerbyDatabase) 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 2 with DerbyDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithDerbyDatabase.

@Test
public void testAutoIncrementStartWithDerbyDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof DerbyDatabase) {
            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 CATALOG_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0))", generatedSql[0].toSql());
        }
    }
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) DerbyDatabase(liquibase.database.core.DerbyDatabase) 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 3 with DerbyDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByDerbyDatabase.

@Test
public void testAutoIncrementStartWithIncrementByDerbyDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof DerbyDatabase) {
            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 CATALOG_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0, INCREMENT BY 10))", generatedSql[0].toSql());
        }
    }
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) DerbyDatabase(liquibase.database.core.DerbyDatabase) 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 4 with DerbyDatabase

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

the class StandardLockService method init.

@Override
public void init() throws DatabaseException {
    boolean createdTable = false;
    Executor executor = ExecutorService.getInstance().getExecutor(database);
    if (!hasDatabaseChangeLogLockTable()) {
        try {
            executor.comment("Create Database Lock Table");
            executor.execute(new CreateDatabaseChangeLogLockTableStatement());
            database.commit();
            LogFactory.getLogger().debug("Created database lock table with name: " + database.escapeTableName(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName()));
        } catch (DatabaseException e) {
            if (e.getMessage() != null && e.getMessage().contains("exists")) {
                //hit a race condition where the table got created by another node.
                LogFactory.getLogger().debug("Database lock table already appears to exist, due to exception: " + e.getMessage() + ". Continuing on");
            } else {
                throw e;
            }
        }
        this.hasDatabaseChangeLogLockTable = true;
        createdTable = true;
        hasDatabaseChangeLogLockTable = true;
    }
    if (!isDatabaseChangeLogLockTableInitialized(createdTable)) {
        executor.comment("Initialize Database Lock Table");
        executor.execute(new InitializeDatabaseChangeLogLockTableStatement());
        database.commit();
    }
    if (executor.updatesDatabase() && database instanceof DerbyDatabase && ((DerbyDatabase) database).supportsBooleanDataType()) {
        //check if the changelog table is of an old smallint vs. boolean format
        String lockTable = database.escapeTableName(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName());
        Object obj = executor.queryForObject(new RawSqlStatement("select min(locked) as test from " + lockTable + " fetch first row only"), Object.class);
        if (!(obj instanceof Boolean)) {
            //wrong type, need to recreate table
            executor.execute(new DropTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName(), false));
            executor.execute(new CreateDatabaseChangeLogLockTableStatement());
            executor.execute(new InitializeDatabaseChangeLogLockTableStatement());
        }
    }
}
Also used : Executor(liquibase.executor.Executor) DerbyDatabase(liquibase.database.core.DerbyDatabase) DatabaseException(liquibase.exception.DatabaseException)

Example 5 with DerbyDatabase

use of liquibase.database.core.DerbyDatabase 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)

Aggregations

DerbyDatabase (liquibase.database.core.DerbyDatabase)5 DB2Database (liquibase.database.core.DB2Database)4 H2Database (liquibase.database.core.H2Database)4 MySQLDatabase (liquibase.database.core.MySQLDatabase)4 OracleDatabase (liquibase.database.core.OracleDatabase)4 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)4 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)4 Database (liquibase.database.Database)3 HsqlDatabase (liquibase.database.core.HsqlDatabase)3 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)3 PostgresDatabase (liquibase.database.core.PostgresDatabase)3 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)3 SybaseDatabase (liquibase.database.core.SybaseDatabase)3 Sql (liquibase.sql.Sql)3 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)3 CreateTableStatement (liquibase.statement.core.CreateTableStatement)3 Test (org.junit.Test)3 DatabaseException (liquibase.exception.DatabaseException)1 Executor (liquibase.executor.Executor)1 MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)1