use of liquibase.sql.Sql in project liquibase by liquibase.
the class SetNullableGeneratorTest method testGenerateOracleNotNullSql.
@Test
public void testGenerateOracleNotNullSql() throws Exception {
final Sql[] sqls = generator.generateSql(new SetNullableStatement(null, "schema_name", "table_name", "column_name", null, false), oracle, null);
assertEquals(1, sqls.length);
final Sql sql = sqls[0];
assertEquals("ALTER TABLE schema_name.table_name MODIFY column_name NOT NULL", sql.toSql());
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class TagDatabaseGeneratorTest method testHsql.
@Test
public void testHsql() throws Exception {
TagDatabaseStatement statement = new TagDatabaseStatement("v1.0");
Sql[] sql = SqlGeneratorFactory.getInstance().generateSql(statement, new HsqlDatabase());
assertEquals(1, sql.length);
assertEquals("UPDATE DATABASECHANGELOG " + "SET TAG = 'v1.0' " + "WHERE DATEEXECUTED = (" + "SELECT MAX(DATEEXECUTED) " + "FROM DATABASECHANGELOG" + ")", sql[0].toSql());
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class UpdateGeneratorTest method testGenerateSqlWithParamPlaceholders.
@Test
public void testGenerateSqlWithParamPlaceholders() {
// given
Database database = new MSSQLDatabase();
UpdateStatement statement = new UpdateStatement(null, null, "DATABASECHANGELOG").addNewColumnValue("MD5SUM", "7:e27bf9c0c2313160ef960a15d44ced47").setWhereClause(database.escapeObjectName("ID", Column.class) + " = ? " + "AND " + database.escapeObjectName("AUTHOR", Column.class) + " = ? " + "AND " + database.escapeObjectName("FILENAME", Column.class) + " = ?").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());
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementBySybaseDatabase.
@Test
public void testAutoIncrementStartWithIncrementBySybaseDatabase() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof SybaseDatabase) {
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 Sybase
assertEquals("CREATE TABLE [SCHEMA_NAME].[TABLE_NAME] ([COLUMN1_NAME] BIGINT IDENTITY NULL)", generatedSql[0].toSql());
}
}
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class DropColumnGeneratorTest method testDropMultipleColumnsMySQL.
@Test
public void testDropMultipleColumnsMySQL() {
DropColumnStatement drop = new DropColumnStatement(Arrays.asList(new DropColumnStatement(null, null, "TEST_TABLE", "col1"), new DropColumnStatement(null, null, "TEST_TABLE", "col2")));
Assert.assertFalse(generatorUnderTest.validate(drop, new MySQLDatabase(), new MockSqlGeneratorChain()).hasErrors());
Sql[] sql = generatorUnderTest.generateSql(drop, new MySQLDatabase(), new MockSqlGeneratorChain());
Assert.assertEquals(1, sql.length);
Assert.assertEquals("ALTER TABLE TEST_TABLE DROP col1, DROP col2", sql[0].toSql());
Assert.assertEquals("[DEFAULT, TEST_TABLE, TEST_TABLE.col1, TEST_TABLE.col2]", String.valueOf(sql[0].getAffectedDatabaseObjects()));
}
Aggregations