Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate deployment ID for all update family commands (DAT-16240) #5185

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package liquibase.extension.testing.command


import liquibase.change.ColumnConfig
import liquibase.change.core.CreateTableChange
import liquibase.change.core.TagDatabaseChange
import liquibase.exception.CommandValidationException
import liquibase.util.TestUtil

CommandTests.define {
command = ["changelogSync"]
Expand Down Expand Up @@ -70,6 +72,10 @@ Optional Args:
),
]
}

expectations = {
TestUtil.assertAllDeploymentIdsNonNull()
}
}

run "Run without URL should throw an exception", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package liquibase.extension.testing.command

import liquibase.exception.CommandValidationException
import liquibase.util.TestUtil

CommandTests.define {
command = ["markNextChangesetRan"]
Expand Down Expand Up @@ -38,6 +39,10 @@ Optional Args:
password : { it.password },
changelogFile: "changelogs/h2/complete/simple.changelog.xml"
]

expectations = {
TestUtil.assertAllDeploymentIdsNonNull()
}
}

run "Run without a URL throws an exception", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package liquibase.extension.testing.command


import liquibase.exception.CommandValidationException
import liquibase.util.TestUtil

CommandTests.define {
command = ["tag"]
Expand Down Expand Up @@ -34,6 +36,10 @@ Optional Args:
password: { it.password },
tag: "version_2.0"
]

expectations = {
TestUtil.assertAllDeploymentIdsNonNull()
}
}

run "Run without a tag should throw an exception", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import liquibase.exception.CommandValidationException
import java.util.regex.Pattern

import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull

CommandTests.define {
command = ["update"]
Expand Down Expand Up @@ -76,6 +77,7 @@ Optional Args:
for (RanChangeSet ranChangeSet : ranChangeSets) {
assertEquals(expectedOrder, ranChangeSet.getOrderExecuted())
expectedOrder++
assertNotNull(ranChangeSet.getDeploymentId())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package liquibase.extension.testing.command


import liquibase.exception.CommandValidationException
import liquibase.util.TestUtil

CommandTests.define {
command = ["updateCount"]
Expand Down Expand Up @@ -54,6 +56,10 @@ Optional Args:
defaultChangeExecListener: 'not_null',
updateReport: 'not_null'
]

expectations = {
TestUtil.assertAllDeploymentIdsNonNull()
}
}

run "Happy path with verbose summary output", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package liquibase.extension.testing.command

import liquibase.exception.CommandValidationException

import java.util.regex.Pattern
import liquibase.exception.CommandValidationException
import liquibase.util.TestUtil

CommandTests.define {
command = ["updateTestingRollback"]
Expand Down Expand Up @@ -49,6 +49,10 @@ Optional Args:
runChangelog "changelogs/h2/complete/rollback.changelog.xml"
rollback 5, "changelogs/h2/complete/rollback.changelog.xml"
}

expectations = {
TestUtil.assertAllDeploymentIdsNonNull()
}
}

run "Run without a URL throws an exception", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package liquibase.extension.testing.command


import liquibase.exception.CommandValidationException
import liquibase.util.TestUtil

CommandTests.define {
command = ["updateToTag"]
Expand Down Expand Up @@ -55,6 +57,10 @@ Optional Args:
defaultChangeExecListener: 'not_null',
updateReport: 'not_null'
]

expectations = {
TestUtil.assertAllDeploymentIdsNonNull()
}
}

run "Happy path with a change set that has complicated labels and contexts", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ public void run(CommandResultsBuilder resultsBuilder) throws Exception {
}
if(!isDBLocked) {
LockServiceFactory.getInstance().getLockService(database).waitForLock();
// waitForLock resets the changelog history service, so we need to rebuild that and generate a final deploymentId.
ChangeLogHistoryService changeLogHistoryService = Scope.getCurrentScope().getSingleton(ChangeLogHistoryServiceFactory.class).getChangeLogService(database);
changeLogHistoryService.generateDeploymentId();
}

// waitForLock resets the changelog history service, so we need to rebuild that and generate a final deploymentId.
ChangeLogHistoryService changelogService = Scope.getCurrentScope().getSingleton(ChangeLogHistoryServiceFactory.class).getChangeLogService(database);
changelogService.generateDeploymentId();

Scope.getCurrentScope().addMdcValue(MdcKey.DEPLOYMENT_ID, changelogService.getDeploymentId());
Scope.getCurrentScope().getLog(getClass()).info(String.format("Using deploymentId: %s", changelogService.getDeploymentId()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import liquibase.LabelExpression;
import liquibase.RuntimeEnvironment;
import liquibase.Scope;
import liquibase.changelog.ChangeLogHistoryServiceFactory;
import liquibase.changelog.ChangeLogIterator;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.changelog.filter.*;
Expand Down Expand Up @@ -44,6 +45,8 @@ public void run(CommandResultsBuilder resultsBuilder) throws Exception {
Contexts contexts = ((Contexts) commandScope.getDependency(Contexts.class));
LabelExpression labelExpression = ((LabelExpression) commandScope.getDependency(LabelExpression.class));

Scope.getCurrentScope().getSingleton(ChangeLogHistoryServiceFactory.class).getChangeLogService(database).generateDeploymentId();

ChangeLogIterator logIterator = new ChangeLogIterator(changeLog,
new NotRanChangeSetFilter(database.getRanChangeSetList()),
new ContextChangeSetFilter(contexts),
Expand Down
14 changes: 14 additions & 0 deletions liquibase-standard/src/test/groovy/liquibase/util/TestUtil.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package liquibase.util

import liquibase.ExtensibleObject
import liquibase.Scope
import liquibase.changelog.ChangeLogHistoryServiceFactory
import liquibase.changelog.RanChangeSet
import liquibase.database.Database

import java.lang.reflect.Modifier

import static org.junit.Assert.assertNotNull

/**
* Test-centric utility methods
*/
Expand Down Expand Up @@ -138,4 +144,12 @@ public abstract class TestUtil {
return true;
}

static void assertAllDeploymentIdsNonNull() {
def database = (Database) Scope.getCurrentScope().get("database", null)
def changelogHistoryService = Scope.getCurrentScope().getSingleton(ChangeLogHistoryServiceFactory.class).getChangeLogService(database)
List<RanChangeSet> ranChangeSets = changelogHistoryService.getRanChangeSets()
for (RanChangeSet ranChangeSet : ranChangeSets) {
assertNotNull(ranChangeSet.getDeploymentId())
}
}
}