Store Snapshots, Diffs, and SQL Output from Liquibase in Azure Blob Storage
Liquibase can generate output files during certain commands, such as snapshots, diffs, and files with SQL commands. By using Azure Blob Storage as the destination for these files, you can centralize artifacts for auditing, collaboration, and CI/CD workflows.
This article shows you how to store files Liquibase generated directly in Azure Blob Storage using the --output-file
option. You’ll learn which commands produce these outputs, when to use them, and how to specify an Azure storage path using the az:// URL format.
Requirements
- Liquibase 4.32.0+
- Liquibase Pro license.
- Azure storage account
Prerequisites
- Add the Storage Blob Data Contributor condition to your storage account using role assignment in Azure
- Install the Liquibase Azure extension
- How to Apply Your Liquibase Pro License Key
- Connect Liquibase to Azure Blob Storage
Storing each file type in Azure Blob Storage
Liquibase can generate several types of output files that help you analyze or preview database changes. By using the --output-file
flag with an az://
path, you can store these files directly in your Azure Blob Storage container for centralized access.
Store a snapshot
Use the snapshot command when you want to capture the current structure of your database as a reference point. This is useful for auditing, version control, or pre-migration analysis.
Before you run the example code, be sure to:
- Replace your_blob_container with the name of your blob storage container in Azure where you would like to upload the file.
- Replace test-snapshot.json with your preferred output file name, if desired.
Example Code
liquibase snapshot \
--snapshot-format=json \
--output-file="az://your_blob_container/test-snapshot.json"
Store a diff
The diff
command compares two databases and generates a difference report. It’s commonly used at the end of a project to verify that all changes are captured in the changelog, or to detect drift between an expected schema and the actual state of a database.
Before you run the example code, be sure to:
- Replace your_blob_container with the name of your blob storage container in Azure where you would like to upload the file.
- Replace test-diff.txt with your preferred output file name, if desired.
- Update the
--reference-url
value to match the connection string for your reference database. This is the source database you want to compare from. - Update the
--url
value to match the connection string for your target database. This is the database you are using to compare against.
Example Code
liquibase diff \
--reference-url=jdbc:h2:mem:reference \
--url=jdbc:h2:mem:target \
--output-file="az://your_blob_container/test-diff.txt"
Store SQL output
The updateSQL
command generates the SQL statements from the changelog and saves them as a preview file, rather than running them on a database. This is often used for code review, audits, or manual application in locked-down environments.
Before you run the example code, be sure to:
- Replace your_blob_container with the name of your blob storage container in Azure where you would like to upload the file.
- Replace your_changelog.sql with the file name for your changelog file.
- Replace update-preview.sql with your preferred output file name, if desired.
Note: This example assumes you already have a changelog file stored in an Azure Blob container that you would like to use. You can also reference a changelog from a local directory.
Example Code
liquibase updateSQL \
--changelog-file=az://your_blob_container/your_changelog.sql \
--output-file="az://your_blob_container/update-preview.sql"
Verify your file is stored
After running each command to store a file in Azure, be sure to navigate to your Azure Blob Storage container in the Azure portal to confirm that the file was successfully uploaded.