Search in sources :

Example 11 with MySQLDatabase

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

the class AddColumnGeneratorTest method testAddMultipleColumnsMySql.

@Test
public void testAddMultipleColumnsMySql() {
    AddColumnStatement columns = new AddColumnStatement(new AddColumnStatement(null, null, TABLE_NAME, "column1", "INT", null, new NotNullConstraint()), new AddColumnStatement(null, null, TABLE_NAME, "column2", "INT", null, new NotNullConstraint()));
    assertFalse(generatorUnderTest.validate(columns, new MySQLDatabase(), new MockSqlGeneratorChain()).hasErrors());
    Sql[] sql = generatorUnderTest.generateSql(columns, new MySQLDatabase(), new MockSqlGeneratorChain());
    assertEquals(1, sql.length);
    assertEquals("ALTER TABLE " + TABLE_NAME + " ADD column1 INT NOT NULL, ADD column2 INT NOT NULL", sql[0].toSql());
    assertEquals("[DEFAULT, table_name, table_name.column1, table_name.column2]", String.valueOf(sql[0].getAffectedDatabaseObjects()));
}
Also used : MySQLDatabase(liquibase.database.core.MySQLDatabase) AddColumnStatement(liquibase.statement.core.AddColumnStatement) NotNullConstraint(liquibase.statement.NotNullConstraint) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Sql(liquibase.sql.Sql) Test(org.junit.Test) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest)

Example 12 with MySQLDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByMySQLDatabase.

@Test
public void testAutoIncrementStartWithIncrementByMySQLDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof MySQLDatabase) {
            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);
            // increment by not supported by MySQL
            assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME BIGINT AUTO_INCREMENT NULL) AUTO_INCREMENT=2", 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) MySQLDatabase(liquibase.database.core.MySQLDatabase) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 13 with MySQLDatabase

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

the class DiffToChangeLogTest method getOrderedOutputTypes_isConsistant.

@Test
public void getOrderedOutputTypes_isConsistant() throws Exception {
    MySQLDatabase database = new MySQLDatabase();
    DiffToChangeLog obj = new DiffToChangeLog(new DiffResult(new EmptyDatabaseSnapshot(database), new EmptyDatabaseSnapshot(database), new CompareControl()), null);
    for (Class<? extends ChangeGenerator> type : new Class[] { UnexpectedObjectChangeGenerator.class, MissingObjectChangeGenerator.class, ChangedObjectChangeGenerator.class }) {
        List<Class<? extends DatabaseObject>> orderedOutputTypes = obj.getOrderedOutputTypes(type);
        for (int i = 0; i < 50; i++) {
            assertThat("Error checking " + type.getName(), orderedOutputTypes, contains(obj.getOrderedOutputTypes(type).toArray()));
        }
    }
}
Also used : MySQLDatabase(liquibase.database.core.MySQLDatabase) EmptyDatabaseSnapshot(liquibase.snapshot.EmptyDatabaseSnapshot) CompareControl(liquibase.diff.compare.CompareControl) DatabaseObject(liquibase.structure.DatabaseObject) DiffResult(liquibase.diff.DiffResult) Test(org.junit.Test)

Example 14 with MySQLDatabase

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

the class JdbcExecutorTest method getInstance.

@Test
public void getInstance() {
    final Database oracle1 = new OracleDatabase() {

        @Override
        public boolean equals(Object o) {
            return o == this;
        }
    };
    final Database oracle2 = new OracleDatabase() {

        @Override
        public boolean equals(Object o) {
            return o == this;
        }
    };
    final Database mysql = new MySQLDatabase() {

        @Override
        public boolean equals(Object o) {
            return o == this;
        }
    };
    assertNotNull(ExecutorService.getInstance().getExecutor(oracle1));
    assertNotNull(ExecutorService.getInstance().getExecutor(oracle2));
    assertNotNull(ExecutorService.getInstance().getExecutor(mysql));
    assertTrue(ExecutorService.getInstance().getExecutor(oracle1) == ExecutorService.getInstance().getExecutor(oracle1));
    assertTrue(ExecutorService.getInstance().getExecutor(oracle2) == ExecutorService.getInstance().getExecutor(oracle2));
    assertTrue(ExecutorService.getInstance().getExecutor(mysql) == ExecutorService.getInstance().getExecutor(mysql));
    assertTrue(ExecutorService.getInstance().getExecutor(oracle1) != ExecutorService.getInstance().getExecutor(oracle2));
    assertTrue(ExecutorService.getInstance().getExecutor(oracle1) != ExecutorService.getInstance().getExecutor(mysql));
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) Database(liquibase.database.Database) MySQLDatabase(liquibase.database.core.MySQLDatabase) Test(org.junit.Test)

Example 15 with MySQLDatabase

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

the class LockServiceFactoryTest method getLockService.

@Test
public void getLockService() {
    final Database oracle1 = new OracleDatabase() {

        @Override
        public boolean equals(Object o) {
            return o == this;
        }
    };
    final Database oracle2 = new OracleDatabase() {

        @Override
        public boolean equals(Object o) {
            return o == this;
        }
    };
    final Database mysql = new MySQLDatabase() {

        @Override
        public boolean equals(Object o) {
            return o == this;
        }
    };
    DatabaseFactory databaseFactory = DatabaseFactory.getInstance();
    databaseFactory.register(oracle1);
    databaseFactory.register(oracle2);
    databaseFactory.register(mysql);
    LockServiceFactory lockServiceFactory = LockServiceFactory.getInstance();
    assertNotNull(lockServiceFactory.getLockService(oracle1));
    assertNotNull(lockServiceFactory.getLockService(oracle2));
    assertNotNull(lockServiceFactory.getLockService(mysql));
    assertTrue(lockServiceFactory.getLockService(oracle1) == lockServiceFactory.getLockService(oracle1));
    assertTrue(lockServiceFactory.getLockService(oracle2) == lockServiceFactory.getLockService(oracle2));
    assertTrue(lockServiceFactory.getLockService(mysql) == lockServiceFactory.getLockService(mysql));
    assertTrue(lockServiceFactory.getLockService(oracle1) != lockServiceFactory.getLockService(oracle2));
    assertTrue(lockServiceFactory.getLockService(oracle1) != lockServiceFactory.getLockService(mysql));
    assertTrue(lockServiceFactory.getLockService(getMockDatabase()) instanceof MockLockService);
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) MockLockService(liquibase.lockservice.ext.MockLockService) DatabaseFactory(liquibase.database.DatabaseFactory) MockDatabase(liquibase.sdk.database.MockDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) Database(liquibase.database.Database) MySQLDatabase(liquibase.database.core.MySQLDatabase) Test(org.junit.Test)

Aggregations

MySQLDatabase (liquibase.database.core.MySQLDatabase)21 Test (org.junit.Test)14 OracleDatabase (liquibase.database.core.OracleDatabase)9 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)7 Sql (liquibase.sql.Sql)7 H2Database (liquibase.database.core.H2Database)6 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)6 Database (liquibase.database.Database)5 DB2Database (liquibase.database.core.DB2Database)5 PostgresDatabase (liquibase.database.core.PostgresDatabase)5 DerbyDatabase (liquibase.database.core.DerbyDatabase)4 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)4 MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)4 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)4 CreateTableStatement (liquibase.statement.core.CreateTableStatement)4 HsqlDatabase (liquibase.database.core.HsqlDatabase)3 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)3 SybaseDatabase (liquibase.database.core.SybaseDatabase)3 LiquibaseDataType (liquibase.datatype.LiquibaseDataType)3 AddColumnStatement (liquibase.statement.core.AddColumnStatement)3