use of liquibase.changelog.ChangeSet in project liquibase by liquibase.
the class ChangeSetExecutedPrecondition method check.
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
ObjectQuotingStrategy objectQuotingStrategy = null;
if (changeSet == null) {
objectQuotingStrategy = ObjectQuotingStrategy.LEGACY;
} else {
objectQuotingStrategy = changeSet.getObjectQuotingStrategy();
}
String changeLogFile = getChangeLogFile();
if (changeLogFile == null) {
changeLogFile = changeLog.getLogicalFilePath();
}
ChangeSet interestedChangeSet = new ChangeSet(getId(), getAuthor(), false, false, changeLogFile, null, null, false, objectQuotingStrategy, changeLog);
RanChangeSet ranChangeSet;
try {
ranChangeSet = database.getRanChangeSet(interestedChangeSet);
} catch (Exception e) {
throw new PreconditionErrorException(e, changeLog, this);
}
if (ranChangeSet == null || ranChangeSet.getExecType() == null || !ranChangeSet.getExecType().ran) {
throw new PreconditionFailedException("Change Set '" + interestedChangeSet.toString(false) + "' has not been run", changeLog, this);
}
}
use of liquibase.changelog.ChangeSet in project minijax by minijax.
the class LiquibaseHelperTest method testFilterChangeSets.
@Test
public void testFilterChangeSets() {
final DropTableChange c1 = new DropTableChange();
c1.setTableName("foo");
final ChangeSet cs1 = new ChangeSet(null);
cs1.addChange(c1);
final DropTableChange c2 = new DropTableChange();
c2.setTableName("JGROUPSPING");
final ChangeSet cs2 = new ChangeSet(null);
cs2.addChange(c2);
final List<ChangeSet> original = Arrays.asList(cs1, cs2);
final List<ChangeSet> filtered = LiquibaseHelper.filterChangeSets(original);
assertEquals(1, filtered.size());
assertEquals(c1, filtered.get(0).getChanges().get(0));
}
use of liquibase.changelog.ChangeSet in project minijax by minijax.
the class LiquibaseHelperTest method testIgnoreChangeSet.
@Test
public void testIgnoreChangeSet() {
final DropTableChange change = new DropTableChange();
change.setTableName("JGROUPSPING");
final ChangeSet changeSet = new ChangeSet(null);
changeSet.addChange(change);
assertTrue(LiquibaseHelper.isIgnoredChangeSet(changeSet));
}
use of liquibase.changelog.ChangeSet in project minijax by minijax.
the class LiquibaseHelper method generateMigrations.
private File generateMigrations(final Database referenceDatabase, final Database targetDatabase) throws LiquibaseException, IOException {
if (!resourcesDir.exists()) {
resourcesDir.mkdirs();
}
if (!migrationsDir.exists()) {
migrationsDir.mkdirs();
}
if (masterChangeLogFile.exists()) {
LOG.info("Checking current database state");
validateDatabaseState(targetDatabase);
} else {
LOG.info("Creating new master changelog");
writeChangeSets(masterChangeLogFile, emptyList());
}
@SuppressWarnings("unchecked") final SnapshotControl snapshotControl = new SnapshotControl(referenceDatabase, liquibase.structure.core.Schema.class, liquibase.structure.core.Table.class, liquibase.structure.core.Column.class, liquibase.structure.core.PrimaryKey.class, liquibase.structure.core.Index.class);
LOG.info("Executing diff");
final CompareControl compareControl = new CompareControl(snapshotControl.getTypesToInclude());
final DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(referenceDatabase, targetDatabase, compareControl);
LOG.info("Converting diff to changelog");
final DiffOutputControl diffOutputControl = new DiffOutputControl(false, false, true, null);
final DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffResult, diffOutputControl);
diffToChangeLog.setChangeSetAuthor(System.getProperty("user.name"));
final List<ChangeSet> changeSets = filterChangeSets(diffToChangeLog.generateChangeSets());
LOG.info("Found {} changes", changeSets.size());
if (changeSets.isEmpty()) {
return null;
}
final File generatedChangeLogFile = new File(migrationsDir, generateFileName(masterChangeLogFile));
LOG.info("Writing new changelog: {}", generatedChangeLogFile);
writeChangeSets(generatedChangeLogFile, changeSets);
LOG.info("Add migration to master changelog: {}", masterChangeLogFile);
addIncludeFile(generatedChangeLogFile);
LOG.info("Cleaning changelog");
cleanXmlFile(masterChangeLogFile);
cleanXmlFile(generatedChangeLogFile);
LOG.info("Diff complete");
return generatedChangeLogFile;
}
use of liquibase.changelog.ChangeSet in project webcert by sklintyg.
the class DbChecker method checkDb.
@PostConstruct
public void checkDb() {
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
Liquibase liquibase = new Liquibase(script, new ClassLoaderResourceAccessor(), database);
LOG.info("Checking database: {} URL:{}", database.getDatabaseProductName(), database.getConnection().getURL());
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(null, liquibase.getChangeLogParameters().getLabels());
if (!changeSets.isEmpty()) {
StringBuilder errors = new StringBuilder();
for (ChangeSet changeSet : changeSets) {
errors.append('>').append(changeSet.toString()).append('\n');
}
throw new Error("Database version mismatch. Check liquibase status. Errors:\n" + errors.toString() + database.getDatabaseProductName() + ", " + database);
}
} catch (liquibase.exception.LiquibaseException | SQLException e) {
throw new Error("Database not ok, aborting startup.", e);
}
LOG.info("Liquibase ok");
}
Aggregations