I’m having an issue with Liquibase when I tried to rollback a changeset by tag. Rollback by count is working correctly.
Using: Liquibase version 4.17.2 and running it inside a docker container.
Changesets:
--liquibase formatted sql
--changeset freskim:testing-data
CREATE TABLE [dbo].[testingTable](
[AlertProfileId] [int] NOT NULL,
[ExternalUserId] [nvarchar](450) NOT NULL
) ON [PRIMARY];
--rollback drop table testingTable;
--changeset freskim:testing2-data
CREATE TABLE [dbo].[test2Table](
[AlertProfileId] [int] NOT NULL,
[ExternalUserId] [nvarchar](450) NOT NULL
) ON [PRIMARY];
--rollback drop table test2Table;
Master database changelog
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
<!-- TIVE : MSSQL TiveCacheDb : CHANGE LOG FILES -->
<includeAll path="schema-changelog" relativeToChangelogFile="true"></includeAll>
</databaseChangeLog>
I’m running liquibase using a Powershell:
param(
[Parameter(Mandatory=$true)]
[String]$Environment,
[Parameter(Mandatory=$true)]
[String]$LiquibaseTag,
[Parameter(Mandatory=$true)]
[String]$AWS_Profile,
[Parameter(Mandatory=$true)]
[String]$Region
)
# Stop the script if we run into errors
$ErrorActionPreference = "Stop"
Write-Host $MyInvocation.MyCommand.Path.
[String]$AccountId = aws sts get-caller-identity --query Account --profile $AWS_Profile --output text
$Repository = "${AccountId}.dkr.ecr.${Region}.amazonaws.com"
$BuildTag = "tive-liquibase:$Environment"
$ImagePath = "$Repository/$BuildTag"
# Log in to ECR
aws ecr get-login-password --region $Region --profile $AWS_Profile | docker login --username AWS --password-stdin $Repository
$MyExitCode = $?
if (!$MyExitCode)
{
Write-Host "Failed to login to ECR repository: $MyExitCode"
exit $MyExitCode
}
#Pull Docker Image locally
docker pull $ImagePath
$MyExitCode = $?
if (!$MyExitCode)
{
Write-Host "Failed to pull image from ECR repository: $MyExitCode"
exit $MyExitCode
}
[String]$secrets = aws secretsmanager get-secret-value --secret-id liquibase-test `
--query SecretString --output text --profile $AWS_Profile
$GetSecrets = ConvertFrom-Json $secrets
[String]$DatabaseHost = $GetSecrets.host
[String]$DatabasePort = $GetSecrets.port
[String]$Username = $GetSecrets.username
[String]$Password = $GetSecrets.password
#Rune Schema Rollback by Tag
Write-Host "Run Schema Rollback by Tag"
$Databases = @('TiveCacheDb')
foreach ($Database in $Databases) {
$ChangeLogFile = "mssql/$Database/db.change-log.xml"
$URL= "jdbc:sqlserver://${DatabaseHost}:${DatabasePort};databaseName=$Database;trustServerCertificate=true"
docker run --rm -v $PWD/liquibase/changelog:/liquibase/changelog $ImagePath --url=$URL `
--changeLogFile=$ChangeLogFile --driver=com.microsoft.sqlserver.jdbc.SQLServerDriver `
--username=$Username --password=$Password rollback $LiquibaseTag
}
$MyExitCode = $?
if (!$MyExitCode)
{
Write-Host "Failed to Rollback by Tag, reason: $MyExitCode"
exit $MyExitCode
}
Here is the hierarchy of my files