Search in sources :

Example 6 with SQLiteDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementBySQLiteDatabase.

@Test
public void testAutoIncrementStartWithIncrementBySQLiteDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof SQLiteDatabase) {
            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), BigInteger.TEN));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            // start with and increment by not supported by SQLite
            assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT AUTOINCREMENT)", generatedSql[0].toSql());
        }
    }
}
Also used : SQLiteDatabase(liquibase.database.core.SQLiteDatabase) 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) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 7 with SQLiteDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithSQLiteDatabase.

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

Example 8 with SQLiteDatabase

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

the class TestContext method getAllDatabases.

public Set<Database> getAllDatabases() {
    if (allDatabases == null) {
        allDatabases = new HashSet<Database>();
        allDatabases.addAll(DatabaseFactory.getInstance().getImplementedDatabases());
        List<Database> toRemove = new ArrayList<Database>();
        for (Database database : allDatabases) {
            if (// todo: re-enable sqlite testing
            (database instanceof SQLiteDatabase) || (database instanceof MockDatabase)) {
                toRemove.add(database);
            }
            database.setCanCacheLiquibaseTableInfo(false);
        }
        allDatabases.removeAll(toRemove);
    }
    return allDatabases;
}
Also used : SQLiteDatabase(liquibase.database.core.SQLiteDatabase) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) Database(liquibase.database.Database) MockDatabase(liquibase.database.core.MockDatabase) ArrayList(java.util.ArrayList) MockDatabase(liquibase.database.core.MockDatabase)

Example 9 with SQLiteDatabase

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

the class DatabaseTestContext method getAllDatabases.

public Set<Database> getAllDatabases() {
    if (allDatabases == null) {
        allDatabases = new HashSet<Database>();
        allDatabases.addAll(DatabaseFactory.getInstance().getImplementedDatabases());
        List<Database> toRemove = new ArrayList<Database>();
        for (Database database : allDatabases) {
            if (//todo: re-enable sqlite testing
            database instanceof SQLiteDatabase || database instanceof MockDatabase || database instanceof ExampleCustomDatabase) {
                toRemove.add(database);
            }
        }
        allDatabases.removeAll(toRemove);
    }
    return allDatabases;
}
Also used : SQLiteDatabase(liquibase.database.core.SQLiteDatabase) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DB2Database(liquibase.database.core.DB2Database) MockDatabase(liquibase.sdk.database.MockDatabase) ExampleCustomDatabase(liquibase.database.example.ExampleCustomDatabase) MockDatabase(liquibase.sdk.database.MockDatabase) ExampleCustomDatabase(liquibase.database.example.ExampleCustomDatabase)

Example 10 with SQLiteDatabase

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

the class DatabaseTestTemplate method test.

private void test(DatabaseTest test, Set<Database> databasesToTestOn) throws Exception {
    for (Database database : databasesToTestOn) {
        if (database instanceof SQLiteDatabase) {
            //todo: find how to get tests to run correctly on SQLite
            continue;
        }
        JdbcExecutor writeExecutor = new JdbcExecutor();
        writeExecutor.setDatabase(database);
        ExecutorService.getInstance().setExecutor(database, writeExecutor);
        LockService lockService = LockServiceFactory.getInstance().getLockService(database);
        lockService.reset();
        if (database.getConnection() != null) {
            lockService.forceReleaseLock();
        }
        try {
            test.performTest(database);
        } catch (ComparisonFailure e) {
            String newMessage = "Database Test Failure on " + database;
            if (e.getMessage() != null) {
                newMessage += ": " + e.getMessage();
            }
            ComparisonFailure newError = new ComparisonFailure(newMessage, e.getExpected(), e.getActual());
            newError.setStackTrace(e.getStackTrace());
            throw newError;
        } catch (AssertionError e) {
            e.printStackTrace();
            String newMessage = "Database Test Failure on " + database;
            if (e.getMessage() != null) {
                newMessage += ": " + e.getMessage();
            }
            AssertionError newError = new AssertionError(newMessage);
            newError.setStackTrace(e.getStackTrace());
            throw newError;
        } catch (MigrationFailedException e) {
            e.printStackTrace();
            String newMessage = "Database Test Failure on " + database;
            if (e.getMessage() != null) {
                newMessage += ": " + e.getMessage();
            }
            AssertionError newError = new AssertionError(newMessage);
            newError.setStackTrace(e.getStackTrace());
            throw newError;
        } catch (Exception e) {
            e.printStackTrace();
            String newMessage = "Database Test Exception on " + database;
            if (e.getMessage() != null) {
                newMessage += ": " + e.getMessage();
            }
            Exception newError = e.getClass().getConstructor(String.class).newInstance(newMessage);
            if (e.getCause() == null) {
                newError.setStackTrace(e.getStackTrace());
            } else {
                newError.setStackTrace(e.getCause().getStackTrace());
            }
            throw newError;
        } finally {
            if (database.getConnection() != null && !database.getAutoCommitMode()) {
                database.rollback();
            }
        }
    }
}
Also used : LockService(liquibase.lockservice.LockService) MigrationFailedException(liquibase.exception.MigrationFailedException) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) ComparisonFailure(org.junit.ComparisonFailure) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) Database(liquibase.database.Database) JdbcExecutor(liquibase.executor.jvm.JdbcExecutor) MigrationFailedException(liquibase.exception.MigrationFailedException)

Aggregations

SQLiteDatabase (liquibase.database.core.SQLiteDatabase)18 Database (liquibase.database.Database)8 PostgresDatabase (liquibase.database.core.PostgresDatabase)7 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)6 Sql (liquibase.sql.Sql)6 AbstractDb2Database (liquibase.database.core.AbstractDb2Database)5 DB2Database (liquibase.database.core.DB2Database)5 MySQLDatabase (liquibase.database.core.MySQLDatabase)5 OracleDatabase (liquibase.database.core.OracleDatabase)5 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)5 SybaseDatabase (liquibase.database.core.SybaseDatabase)5 SqlStatement (liquibase.statement.SqlStatement)5 ArrayList (java.util.ArrayList)4 DerbyDatabase (liquibase.database.core.DerbyDatabase)4 H2Database (liquibase.database.core.H2Database)4 HsqlDatabase (liquibase.database.core.HsqlDatabase)4 ColumnConfig (liquibase.change.ColumnConfig)3 DatabaseException (liquibase.exception.DatabaseException)3 LiquibaseException (liquibase.exception.LiquibaseException)3 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)3