Search in sources :

Example 36 with MSSQLDatabase

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

the class MssqlIntegrationTest method dataTypeParamsTest.

@Test
public void dataTypeParamsTest() throws Exception {
    if (this.getDatabase() == null) {
        return;
    }
    Liquibase liquibase = createLiquibase("changelogs/mssql/issues/data.type.params.xml");
    liquibase.update((String) null);
    DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, this.getDatabase(), new SnapshotControl(getDatabase()));
    for (Table table : snapshot.get(Table.class)) {
        if (getDatabase().isLiquibaseObject(table)) {
            continue;
        }
        for (Column column : table.getColumns()) {
            String expectedType = column.getName().split("_")[0];
            String foundTypeDefinition = DataTypeFactory.getInstance().from(column.getType(), new MSSQLDatabase()).toDatabaseDataType(getDatabase()).toString();
            assertFalse("Parameter found in " + table.getName() + "." + column.getName(), foundTypeDefinition.contains("("));
        }
    }
}
Also used : Liquibase(liquibase.Liquibase) Table(liquibase.structure.core.Table) Column(liquibase.structure.core.Column) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) EmptyDatabaseSnapshot(liquibase.snapshot.EmptyDatabaseSnapshot) SnapshotControl(liquibase.snapshot.SnapshotControl) Test(org.junit.Test)

Example 37 with MSSQLDatabase

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

the class TagDatabaseGeneratorTest method testMSSQL.

////    @Test
////    public void supports() throws Exception {
////        new DatabaseTestTemplate().testOnAllDatabases(new DatabaseTest() {
////            public void performTest(Database database) throws Exception {
////                assertTrue(createGeneratorUnderTest().supportsDatabase(database));
////            }
////        });
////    }
//
//    @Test
//    public void execute() throws Exception {
//        new DatabaseTestTemplate().testOnAvailableDatabases(
//                new SqlStatementDatabaseTest(null, new TagDatabaseStatement("TAG_NAME")) {
//                    protected void setup(Database database) throws Exception {
//                        new Liquibase("changelogs/common/common.tests.changelog.xml", new JUnitResourceAccessor(), database).update(null);
//                    }
//
//                    protected void preExecuteAssert(DatabaseSnapshotGenerator snapshot) throws DatabaseException {
//                        assertFalse(snapshot.getDatabase().doesTagExist("TAG_NAME"));
//                    }
//
//                    protected void postExecuteAssert(DatabaseSnapshotGenerator snapshot) throws DatabaseException {
//                        assertTrue(snapshot.getDatabase().doesTagExist("TAG_NAME"));
//                    }
//
//                });
//    }
@Test
public void testMSSQL() throws Exception {
    TagDatabaseStatement statement = new TagDatabaseStatement("v1.0");
    Sql[] sql = SqlGeneratorFactory.getInstance().generateSql(statement, new MSSQLDatabase());
    assertEquals(1, sql.length);
    assertEquals("UPDATE [changelog] " + "SET [TAG] = 'v1.0' " + "FROM [DATABASECHANGELOG] AS [changelog] " + "INNER JOIN (" + "SELECT TOP (1) [ID], [AUTHOR], [FILENAME] " + "FROM [DATABASECHANGELOG] " + "ORDER BY [DATEEXECUTED] DESC, [ORDEREXECUTED] DESC" + ") AS [latest] " + "ON [latest].[ID] = [changelog].[ID] " + "AND [latest].[AUTHOR] = [changelog].[AUTHOR] " + "AND [latest].[FILENAME] = [changelog].[FILENAME]", sql[0].toSql());
}
Also used : TagDatabaseStatement(liquibase.statement.core.TagDatabaseStatement) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Example 38 with MSSQLDatabase

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

the class UpdateGeneratorTest method testGenerateSqlWithNameValuePlaceholderPairs.

@Test
public void testGenerateSqlWithNameValuePlaceholderPairs() {
    // given
    Database database = new MSSQLDatabase();
    UpdateStatement statement = new UpdateStatement(null, null, "DATABASECHANGELOG").addNewColumnValue("MD5SUM", "7:e27bf9c0c2313160ef960a15d44ced47").setWhereClause(":name = :value AND :name = :value AND :name = :value").addWhereColumnName("ID").addWhereColumnName("AUTHOR").addWhereColumnName("FILENAME").addWhereParameters("SYPA: AUTO_START tüüp INT -> TEXT, vaartus 0 00 17 * * ?", "martin", "db/changelog.xml");
    UpdateGenerator generator = new UpdateGenerator();
    // when
    Sql[] sqls = generator.generateSql(statement, database, null);
    // then
    assertEquals("UPDATE [DATABASECHANGELOG] " + "SET [MD5SUM] = '7:e27bf9c0c2313160ef960a15d44ced47' " + "WHERE [ID] = N'SYPA: AUTO_START tüüp INT -> TEXT, vaartus 0 00 17 * * ?' " + "AND [AUTHOR] = 'martin' " + "AND [FILENAME] = 'db/changelog.xml'", sqls[0].toSql());
}
Also used : UpdateStatement(liquibase.statement.core.UpdateStatement) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Database(liquibase.database.Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Aggregations

MSSQLDatabase (liquibase.database.core.MSSQLDatabase)38 Test (org.junit.Test)17 Sql (liquibase.sql.Sql)12 OracleDatabase (liquibase.database.core.OracleDatabase)11 Database (liquibase.database.Database)7 DB2Database (liquibase.database.core.DB2Database)7 MySQLDatabase (liquibase.database.core.MySQLDatabase)7 PostgresDatabase (liquibase.database.core.PostgresDatabase)7 RawSqlStatement (liquibase.statement.core.RawSqlStatement)6 Column (liquibase.structure.core.Column)6 ArrayList (java.util.ArrayList)5 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)5 DatabaseException (liquibase.exception.DatabaseException)5 Change (liquibase.change.Change)4 HsqlDatabase (liquibase.database.core.HsqlDatabase)4 SybaseDatabase (liquibase.database.core.SybaseDatabase)4 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)4 Executor (liquibase.executor.Executor)4 InsertOrUpdateStatement (liquibase.statement.core.InsertOrUpdateStatement)4 BigInteger (java.math.BigInteger)3