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 1 commit
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
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,7 +1,13 @@
package liquibase.extension.testing.command

import liquibase.Scope
import liquibase.changelog.ChangeLogHistoryServiceFactory
import liquibase.changelog.RanChangeSet
import liquibase.database.Database
import liquibase.exception.CommandValidationException

import static org.junit.Assert.assertNotNull

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

expectations = {
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())
}
}
}

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

import liquibase.Scope
import liquibase.changelog.ChangeLogHistoryServiceFactory
import liquibase.changelog.RanChangeSet
import liquibase.database.Database
import liquibase.exception.CommandValidationException

import java.util.regex.Pattern
import static org.junit.Assert.assertNotNull

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

expectations = {
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())
}
}
}

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

import liquibase.Scope
import liquibase.changelog.ChangeLogHistoryServiceFactory
import liquibase.changelog.RanChangeSet
import liquibase.database.Database
import liquibase.exception.CommandValidationException

import static org.junit.Assert.assertNotNull

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

expectations = {
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())
}
}
}

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