Search in sources :

Example 66 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class ValidatingVisitorTest method setup.

@Before
public void setup() {
    changeSet1 = new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null, null);
    changeSet2 = new ChangeSet("2", "testAuthor", false, false, "path/changelog", null, null, null);
}
Also used : RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) Before(org.junit.Before)

Example 67 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class AbstractIntegrationTest method testGenerateChangeLogWithNoChanges.

@Test
public void testGenerateChangeLogWithNoChanges() throws Exception {
    assumeNotNull(this.getDatabase());
    runCompleteChangeLog();
    DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, database, new CompareControl());
    DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, new DiffOutputControl(false, false, false, null));
    List<ChangeSet> changeSets = changeLogWriter.generateChangeSets();
    assertEquals("generating two change logs without any changes in between should result in an empty generated " + "differential change set.", 0, changeSets.size());
}
Also used : CompareControl(liquibase.diff.compare.CompareControl) DiffOutputControl(liquibase.diff.output.DiffOutputControl) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) DiffResult(liquibase.diff.DiffResult) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 68 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class MarkChangeSetRanExecuteTest method generateSql_insert.

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

Example 69 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class OracleIntegrationTest method sqlplusChangelog.

@Test
public void sqlplusChangelog() throws Exception {
    Database database = this.getDatabase();
    assumeNotNull(database);
    Liquibase liquibase = createLiquibase(this.customExecutorChangeLog);
    clearDatabase();
    // 
    // Add a visitor so we can assert
    // 
    DatabaseChangeLog changeLog = liquibase.getDatabaseChangeLog();
    for (ChangeSet changeSet : changeLog.getChangeSets()) {
        changeSet.addSqlVisitor(new TestSqlVisitor());
    }
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
    database.commit();
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Database(liquibase.database.Database) ChangeSet(liquibase.changelog.ChangeSet) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 70 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class HTMLWriter method writeChanges.

protected void writeChanges(String title, Writer fileWriter, List<Change> changes) throws IOException, DatabaseHistoryException, DatabaseException {
    fileWriter.append("<p><TABLE BORDER=\"1\" WIDTH=\"100%\" CELLPADDING=\"3\" CELLSPACING=\"0\" SUMMARY=\"\">\n");
    fileWriter.append("<TR BGCOLOR=\"#CCCCFF\" CLASS=\"TableHeadingColor\">\n");
    fileWriter.append("<TD COLSPAN='4'><FONT SIZE=\"+2\">\n");
    fileWriter.append("<B>");
    fileWriter.append(title);
    fileWriter.append("</B></FONT></TD>\n");
    fileWriter.append("</TR>\n");
    ChangeSet lastChangeSet = null;
    if ((changes == null) || changes.isEmpty()) {
        fileWriter.append("<tr><td>None Found</td></tr>");
    } else {
        for (Change change : changes) {
            if (!change.getChangeSet().equals(lastChangeSet)) {
                lastChangeSet = change.getChangeSet();
                fileWriter.append("<TR BGCOLOR=\"#EEEEFF\" CLASS=\"TableSubHeadingColor\">\n");
                writeTD(fileWriter, "<a href='../changelogs/" + DBDocUtil.toFileName(change.getChangeSet().getFilePath().toLowerCase()) + ".html'>" + change.getChangeSet().getFilePath() + "</a>");
                writeTD(fileWriter, change.getChangeSet().getId());
                writeTD(fileWriter, "<a href='../authors/" + DBDocUtil.toFileName(change.getChangeSet().getAuthor().toLowerCase()) + ".html'>" + StringUtil.escapeHtml(change.getChangeSet().getAuthor().toLowerCase()) + "</a>");
                ChangeSet.RunStatus runStatus = database.getRunStatus(change.getChangeSet());
                if (runStatus.equals(ChangeSet.RunStatus.NOT_RAN)) {
                    String anchor = change.getChangeSet().toString(false).replaceAll("\\W", "_");
                    writeTD(fileWriter, "NOT YET RAN [<a href='../pending/sql.html#" + anchor + "'>SQL</a>]");
                } else if (runStatus.equals(ChangeSet.RunStatus.INVALID_MD5SUM)) {
                    writeTD(fileWriter, "INVALID MD5SUM");
                } else if (runStatus.equals(ChangeSet.RunStatus.ALREADY_RAN)) {
                    writeTD(fileWriter, "Executed " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(database.getRanDate(change.getChangeSet())));
                } else if (runStatus.equals(ChangeSet.RunStatus.RUN_AGAIN)) {
                    writeTD(fileWriter, "Executed, WILL RUN AGAIN");
                } else {
                    throw new RuntimeException("Unknown run status: " + runStatus);
                }
                fileWriter.append("</TR>");
                if (StringUtil.trimToNull(change.getChangeSet().getComments()) != null) {
                    fileWriter.append("<TR><TD BGCOLOR='#EEEEFF' CLASS='TableSubHeadingColor' colspan='4'>").append(change.getChangeSet().getComments()).append("</TD></TR>");
                }
            }
            fileWriter.append("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">\n");
            fileWriter.append("<td colspan='4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;").append(change.getConfirmationMessage()).append("</td></TR>");
        }
    }
    fileWriter.append("</TABLE>");
    fileWriter.append("&nbsp;</P>");
}
Also used : Change(liquibase.change.Change) ChangeSet(liquibase.changelog.ChangeSet)

Aggregations

ChangeSet (liquibase.changelog.ChangeSet)75 Test (org.junit.Test)41 RanChangeSet (liquibase.changelog.RanChangeSet)13 Contexts (liquibase.Contexts)12 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)11 Database (liquibase.database.Database)11 ArrayList (java.util.ArrayList)10 Liquibase (liquibase.Liquibase)10 Change (liquibase.change.Change)9 LiquibaseException (liquibase.exception.LiquibaseException)9 DiffOutputControl (liquibase.diff.output.DiffOutputControl)7 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)7 IOException (java.io.IOException)6 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)6 DiffResult (liquibase.diff.DiffResult)6 CompareControl (liquibase.diff.compare.CompareControl)6 LabelExpression (liquibase.LabelExpression)5 Sql (liquibase.sql.Sql)5 SqlStatement (liquibase.statement.SqlStatement)5 MarkChangeSetRanStatement (liquibase.statement.core.MarkChangeSetRanStatement)5