public ChangeIncremental withDrop(boolean drop) { this.setDrop(drop); return this; }
@Override public String getCommandDescription() { return "Baseline change " + this.source + " specified these changes to deploy [" + this.source.getBaselinedChanges() + "], but these changes [" + this.nonDeployedChanges + "] were not actually deployed"; }
@Override public String getRollbackToBeExecutedContent() { if (this.rollbackIfAlreadyDeployedContent != null) { return this.rollbackIfAlreadyDeployedContent; } else if (this.rollbackActivated) { return this.getConvertedRollbackContent(); } else { return null; } }
public ChangeIncremental(ChangeKey changeKey, int orderWithinObject, String hash, String content, String rollbackIfAlreadyDeployedContent, boolean active) { this.setChangeKey(changeKey); this.setContentHash(hash); this.setContent(content); this.setOrderWithinObject(orderWithinObject); this.rollbackIfAlreadyDeployedContent = rollbackIfAlreadyDeployedContent; this.setActive(active); }
@Override public Change valueOf(DbCleanCommand cleanCommand) { MutableCollection<Schema> schemas = physicalSchemaToSchemaMap.get(cleanCommand.getPhysicalSchema()); if (cleanCommand.getObjectType().isRerunnable()) { ChangeRerunnable change = new ChangeRerunnable(cleanCommand.getObjectType() , schemas.getFirst().getName() , cleanCommand.getObjectName() , "hash" , "n/a" ); return change; } else { ChangeIncremental dbChangeIncremental = new ChangeIncremental(cleanCommand.getObjectType() , schemas.getFirst().getName() , cleanCommand.getObjectName() , "change" + this.changeIndex++ , 0 , "hash" , cleanCommand.getSqlStatement() ); dbChangeIncremental.setDrop(true); dbChangeIncremental.setManuallyCodedDrop(cleanCommand.getObjectType().getName().equals(ChangeType.FOREIGN_KEY_STR)); dbChangeIncremental.setForceDropForEnvCleaning(true); return dbChangeIncremental; } } });
private void testTableDrops(boolean forceDrop) { Change tabC1Dep = new ChangeIncremental(tableChangeType, "schema", "tabC", "chng1", 0, "tabCExistingToBeDropped", CONTENT); Change tabC1Src = new ChangeIncremental(tableChangeType, "schema", "tabC", tabC1Dep.getChangeName(), 0, "tabCExistingToBeDropped", CONTENT); Change tabC2Src = new ChangeIncremental(tableChangeType, "schema", "tabC", "chng2", 1, "tabCExistingToBeDropped", CONTENT); Change tabC3Src = new ChangeIncremental(tableChangeType, "schema", "tabC", "chng3", 2, "tabCExistingToBeDropped", CONTENT).withDrop(true).withKeepIncrementalOrder(true); Change tabD1Src = new ChangeIncremental(tableChangeType, "schema", "tabD", "cdrop1", 0, "tabDNewTableIsDropped", CONTENT); ChangeIncremental tabD2Src = new ChangeIncremental(tableChangeType, "schema", "tabD", "cdrop2", 1, "tabDNewTableIsDropped", CONTENT).withDrop(true).withKeepIncrementalOrder(true); tabD2Src.setForceDropForEnvCleaning(forceDrop); ListIterable<ChangeCommand> changeset = cmdCalc.calculateCommands(tableChangeType, Lists.mutable.<ChangePair>of( new ChangePair(tabC1Src, tabC1Dep) , new ChangePair(tabC2Src, null) , new ChangePair(tabC3Src, null) , new ChangePair(tabD1Src, null) , new ChangePair(tabD2Src, null) ), unusedChangesArg, false); assertEquals(4, changeset.size()); Verify.assertAnySatisfy(changeset, assertValue(DeployChangeCommand.class, tabC2Src)); Verify.assertAnySatisfy(changeset, assertValue(DropObjectChangeCommand.class, tabC3Src)); if (forceDrop) { // if forceDrop, then ensure that the drops are actually executed Verify.assertAnySatisfy(changeset, assertValue(DeployChangeCommand.class, tabD1Src)); Verify.assertAnySatisfy(changeset, assertValue(DropObjectChangeCommand.class, tabD2Src)); } else { // as tabD was never previously deployed, we should not try to deploy it again Verify.assertAnySatisfy(changeset, assertValue(AlreadyDroppedTableWarning.class, tabD1Src)); Verify.assertAnySatisfy(changeset, assertValue(AlreadyDroppedTableWarning.class, tabD2Src)); } }
@Test public void test() { ChangeType changeType = mock(ChangeType.class); when(changeType.getName()).thenReturn("type"); Platform platform = mock(Platform.class); when(platform.getChangeType(Mockito.anyString())).thenReturn(changeType); MongoDbEnvironment env = mock(MongoDbEnvironment.class); when(env.getPhysicalSchema("mydb")).thenReturn(new PhysicalSchema("mydb")); when(env.getPhysicalSchemas()).thenReturn(Sets.immutable.of(new PhysicalSchema("mydb"))); MongoDbChangeAuditDao changeAuditDao = new MongoDbChangeAuditDao(mongoClient, env, platform, "test"); DeployExecutionImpl exec = new DeployExecutionImpl("requester", "executor", "schema", "1.0.0", new Timestamp(new Date().getTime()), false, false, "1.0.0", "reason", Sets.immutable.<DeployExecutionAttribute>empty()); exec.setId(1L); Change change = new ChangeIncremental(changeType, "mydb", "obj1", "c1", 0, "hash", "content"); changeAuditDao.insertNewChange(change, exec); assertEquals(1, changeAuditDao.getDeployedChanges().size()); } }
@Test public void testBaseline() { Change dep1 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch1", 0, "chng1", CONTENT); Change dep2 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch2", 0, "chng1", CONTENT); Change dep3 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch3", 0, "chng1", CONTENT); Change srcB = new ChangeIncremental(tableChangeType, "schema", "tabB", "bas1", 0, "chng1", CONTENT) .withBaselines(Lists.mutable.with("ch1", "ch2", "ch3")); Change src4 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch4", 1, "chng1", CONTENT); ListIterable<ChangeCommand> changeset = cmdCalc.calculateCommands(tableChangeType, Lists.mutable.of( new ChangePair(srcB, null) , new ChangePair(src4, null) , new ChangePair(null, dep1) , new ChangePair(null, dep2) , new ChangePair(null, dep3) ), unusedChangesArg, false); assertEquals(2, changeset.size()); Verify.assertAnySatisfy(changeset, assertValue(DeployChangeCommand.class, src4)); Predicate<ChangeCommand> baselineCommandPredicate = assertValue(BaselineChangeCommand.class, srcB); Verify.assertAnySatisfy(changeset, baselineCommandPredicate); BaselineChangeCommand baselineCommand = (BaselineChangeCommand) changeset.detect(baselineCommandPredicate); assertEquals(Sets.mutable.with(dep1, dep2, dep3), baselineCommand.getReplacedChanges().toSet()); }
/** * Same input data as the testImproperDroppedSourceChange test, but this time, we run with rollback. Hence, we allow it to go through * without an exception, btu we log a warning message */ @Test public void testDroppedSourceChangeWithRollback() { ChangeIncremental tabE0Dep = new ChangeIncremental(tableChangeType, "schema", "tabE", "0", 0, "chng0", CONTENT); tabE0Dep.setRollbackActivated(true); ListIterable<ChangeCommand> changeset = cmdCalc.calculateCommands(tableChangeType, Lists.mutable.<ChangePair>of( new ChangePair(null, tabE0Dep) ), unusedChangesArg, false); assertEquals(1, changeset.size()); Verify.assertAnySatisfy(changeset, assertValue(UnrolledbackChangeWarning.class, tabE0Dep)); }
@Override public String getCommandDescription() { return "No longer in the source, but will be left in the DB as we are running in rollback mode: " + this.incrementalDeployed.getDisplayString(); }
@Override protected ToStringBuilder toStringBuilder() { return super.toStringBuilder() .append(this.isRollbackIfAlreadyDeployed()); }
public ChangeIncremental() { this.rollbackIfAlreadyDeployedContent = null; this.setActive(true); }
@Override public void undeploy(final Change change) { final ChangeIncremental incrementalDeployed = (ChangeIncremental) change; if (!incrementalDeployed.isRollbackActivated()) { throw new IllegalStateException("Change is intended for rollback, but was not marked as such already; indicates a code issue: " + change); } getSqlExecutor().executeWithinContext(change.getPhysicalSchema(env), new Procedure<Connection>() { @Override public void value(Connection conn) { getBaseArtifactDeployer().deployArtifact(conn, change); } }); }
@Override public Change valueOf(DbCleanCommand cleanCommand) { MutableCollection<Schema> schemas = physicalSchemaToSchemaMap.get(cleanCommand.getPhysicalSchema()); if (cleanCommand.getObjectType().isRerunnable()) { ChangeRerunnable change = new ChangeRerunnable(cleanCommand.getObjectType() , schemas.getFirst().getName() , cleanCommand.getObjectName() , "hash" , "n/a" ); return change; } else { ChangeIncremental dbChangeIncremental = new ChangeIncremental(cleanCommand.getObjectType() , schemas.getFirst().getName() , cleanCommand.getObjectName() , "change" + this.changeIndex++ , 0 , "hash" , cleanCommand.getSqlStatement() ); dbChangeIncremental.setDrop(true); dbChangeIncremental.setManuallyCodedDrop(cleanCommand.getObjectType().getName().equals(ChangeType.FOREIGN_KEY_STR)); dbChangeIncremental.setForceDropForEnvCleaning(true); return dbChangeIncremental; } } });
@Test public void test() { ChangeType changeType = mock(ChangeType.class); when(changeType.getName()).thenReturn("type"); Platform platform = mock(Platform.class); when(platform.getChangeType(Mockito.anyString())).thenReturn(changeType); MongoDbEnvironment env = mock(MongoDbEnvironment.class); when(env.getPhysicalSchema("mydb")).thenReturn(new PhysicalSchema("mydb")); when(env.getPhysicalSchemas()).thenReturn(Sets.immutable.of(new PhysicalSchema("mydb"))); MongoDbChangeAuditDao changeAuditDao = new MongoDbChangeAuditDao(mongoClient, env, platform, "test"); DeployExecutionImpl exec = new DeployExecutionImpl("requester", "executor", "schema", "1.0.0", new Timestamp(new Date().getTime()), false, false, "1.0.0", "reason", Sets.immutable.<DeployExecutionAttribute>empty()); exec.setId(1L); Change change = new ChangeIncremental(changeType, "mydb", "obj1", "c1", 0, "hash", "content"); changeAuditDao.insertNewChange(change, exec); assertEquals(1, changeAuditDao.getDeployedChanges().size()); } }
public ChangeIncremental(ChangeKey changeKey, int orderWithinObject, String hash, String content, String rollbackIfAlreadyDeployedContent, boolean active) { this.setChangeKey(changeKey); this.setContentHash(hash); this.setContent(content); this.setOrderWithinObject(orderWithinObject); this.rollbackIfAlreadyDeployedContent = rollbackIfAlreadyDeployedContent; this.setActive(active); }
@Test public void testBaselineNewAddition() { // dep1, dep2, dep3 are not deployed - hence, we should deploy the baseline we find in the source Change srcB = new ChangeIncremental(tableChangeType, "schema", "tabB", "bas1", 0, "chng1", CONTENT) .withBaselines(Lists.mutable.with("ch1", "ch2", "ch3")); Change src4 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch4", 1, "chng1", CONTENT); ListIterable<ChangeCommand> changeset = cmdCalc.calculateCommands(tableChangeType, Lists.mutable.of( new ChangePair(srcB, null) , new ChangePair(src4, null) ), unusedChangesArg, false); assertEquals(2, changeset.size()); Verify.assertAnySatisfy(changeset, assertValue(DeployChangeCommand.class, srcB)); Verify.assertAnySatisfy(changeset, assertValue(DeployChangeCommand.class, src4)); }
@Override public String getCommandDescription() { return "No longer in the source, but will be left in the DB as we are running in rollback mode: " + this.incrementalDeployed.getDisplayString(); }
@Override protected ToStringBuilder toStringBuilder() { return super.toStringBuilder() .append(this.isRollbackIfAlreadyDeployed()); }
public ChangeIncremental() { this.rollbackIfAlreadyDeployedContent = null; this.setActive(true); }