Search in sources :

Example 1 with MarkChangeSetRanStatement

use of liquibase.statement.core.MarkChangeSetRanStatement in project liquibase by liquibase.

the class MarkChangeSetRanExecuteTest method generateSql_update.

@Test
public void generateSql_update() throws Exception {
    this.statementUnderTest = new MarkChangeSetRanStatement(new ChangeSet("a", "b", false, false, "c", "e", "f", null), ChangeSet.ExecType.RERAN);
    assertCorrect("update [databasechangelog] set [dateexecuted] = NOW(), [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", MSSQLDatabase.class);
    assertCorrect("update [databasechangelog] set [dateexecuted] = SYSTIMESTAMP, [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", OracleDatabase.class);
    assertCorrect("update [databasechangelog] set [dateexecuted] = getdate(), [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", SybaseDatabase.class);
    assertCorrect("update [databasechangelog] set [dateexecuted] = current year to fraction(5), [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", InformixDatabase.class);
    assertCorrect("update [databasechangelog] set [dateexecuted] = current timestamp, [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", DB2Database.class);
    assertCorrect("update [databasechangelog] set [dateexecuted] = current_timestamp, [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", FirebirdDatabase.class, DerbyDatabase.class);
    assertCorrect("update [databasechangelog] set [dateexecuted] = NOW(), [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", SybaseASADatabase.class);
    assertCorrect("update [databasechangelog] set [dateexecuted] = NOW(), [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'", MySQLDatabase.class, HsqlDatabase.class, PostgresDatabase.class, H2Database.class);
    assertCorrectOnRest("update [databasechangelog] set [dateexecuted] = NOW(), [exectype] = 'reran', [md5sum] = '7:d41d8cd98f00b204e9800998ecf8427e' where id='a' and author='b' and filename='c'");
}
Also used : MarkChangeSetRanStatement(liquibase.statement.core.MarkChangeSetRanStatement) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 2 with MarkChangeSetRanStatement

use of liquibase.statement.core.MarkChangeSetRanStatement in project liquibase by liquibase.

the class OfflineChangeLogHistoryService method setExecType.

@Override
public void setExecType(final ChangeSet changeSet, final ChangeSet.ExecType execType) throws DatabaseException {
    if (isExecuteDmlAgainstDatabase()) {
        ExecutorService.getInstance().getExecutor(getDatabase()).execute(new MarkChangeSetRanStatement(changeSet, execType));
        getDatabase().commit();
    }
    if (execType.equals(ChangeSet.ExecType.FAILED) || execType.equals(ChangeSet.ExecType.SKIPPED)) {
        //do nothing
        return;
    } else if (execType.ranBefore) {
        replaceChangeSet(changeSet, new ReplaceChangeSetLogic() {

            @Override
            public String[] execute(String[] line) {
                line[COLUMN_DATEEXECUTED] = new ISODateFormat().format(new java.sql.Timestamp(new Date().getTime()));
                line[COLUMN_MD5SUM] = changeSet.generateCheckSum().toString();
                line[COLUMN_EXECTYPE] = execType.value;
                return line;
            }
        });
    } else {
        appendChangeSet(changeSet, execType);
    }
}
Also used : ISODateFormat(liquibase.util.ISODateFormat) MarkChangeSetRanStatement(liquibase.statement.core.MarkChangeSetRanStatement)

Example 3 with MarkChangeSetRanStatement

use of liquibase.statement.core.MarkChangeSetRanStatement in project liquibase by liquibase.

the class MarkChangeSetRanExecuteTest method generateSql_insert.

@Test
public void generateSql_insert() throws Exception {
    this.statementUnderTest = new MarkChangeSetRanStatement(new ChangeSet("a", "b", false, false, "c", "e", "f", null), ChangeSet.ExecType.EXECUTED);
    String version = LiquibaseUtil.getBuildVersion().replaceAll("SNAPSHOT", "SNP");
    assertCorrect("insert into [databasechangelog] ([id], [author], [filename], [dateexecuted], [orderexecuted], [md5sum], [description], [comments], [exectype], [liquibase]) values ('a', 'b', 'c', getdate(), 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", MSSQLDatabase.class);
    assertCorrect("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', systimestamp, 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", OracleDatabase.class);
    assertCorrect("insert into [databasechangelog] ([id], [author], [filename], [dateexecuted], [orderexecuted], [md5sum], [description], [comments], [exectype], [liquibase]) values ('a', 'b', 'c', getdate(), 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", SybaseDatabase.class);
    assertCorrect("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', current year to fraction(5), 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", InformixDatabase.class);
    assertCorrect("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', current timestamp, 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", DB2Database.class);
    assertCorrect("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', current_timestamp, 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", FirebirdDatabase.class, DerbyDatabase.class);
    assertCorrect("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', now, 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", HsqlDatabase.class);
    assertCorrect("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', now(), 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", SybaseASADatabase.class);
    assertCorrect("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', now(), 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')", MySQLDatabase.class, PostgresDatabase.class, H2Database.class);
    assertCorrectOnRest("insert into databasechangelog (id, author, filename, dateexecuted, orderexecuted, md5sum, description, comments, exectype, liquibase) values ('a', 'b', 'c', current timestamp, 1, '7:d41d8cd98f00b204e9800998ecf8427e', 'empty', '', 'executed', '" + version + "')");
}
Also used : MarkChangeSetRanStatement(liquibase.statement.core.MarkChangeSetRanStatement) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 4 with MarkChangeSetRanStatement

use of liquibase.statement.core.MarkChangeSetRanStatement in project liquibase by liquibase.

the class MarkChangeSetRanGeneratorTest method generateSql_markRan.

@Test
public void generateSql_markRan() {
    Sql[] sqls = new MarkChangeSetRanGenerator().generateSql(new MarkChangeSetRanStatement(new ChangeSet("1", "a", false, false, "c", null, null, null), ChangeSet.ExecType.MARK_RAN), new MockDatabase(), new MockSqlGeneratorChain());
    assertEquals(1, sqls.length);
    assertTrue(sqls[0].toSql(), sqls[0].toSql().contains("MARK_RAN"));
}
Also used : MarkChangeSetRanStatement(liquibase.statement.core.MarkChangeSetRanStatement) MockDatabase(liquibase.sdk.database.MockDatabase) ChangeSet(liquibase.changelog.ChangeSet) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Aggregations

MarkChangeSetRanStatement (liquibase.statement.core.MarkChangeSetRanStatement)4 ChangeSet (liquibase.changelog.ChangeSet)3 Test (org.junit.Test)3 MockDatabase (liquibase.sdk.database.MockDatabase)1 Sql (liquibase.sql.Sql)1 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)1 MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)1 ISODateFormat (liquibase.util.ISODateFormat)1