Rollback SQL step
Last updated on
The Rollback SQL step generates the SQL statements that would be executed during a rollback operation without applying them to the database. It is used for validation, auditing, and policy enforcement before a rollback runs. The generated SQL is surfaced in the Harness UI and can be referenced in downstream approval gates and OPA policy steps.
note
The Rollback SQL step is a Liquibase-only step. It is not available for Flyway migrations.
Before you begin
- DB Schema and DB Instance: You must have at least one DB Schema and one DB Instance configured in Harness Database DevOps. Go to Set up connectors to configure your database connector.
- Tag (for rollback to a specific tag): The target tag must exist in
DATABASECHANGELOG. Go to Using Rollback Tags with Apply Schema to learn how tags are created.
Add the Rollback SQL step
- In Harness, go to Database DevOps and select your project.
- Open your pipeline and select the stage where you want to preview rollback SQL.
- Select Add Step and choose Rollback SQL.
- Configure the step parameters described below.
- Select Apply Changes, then save and run the pipeline.
Step parameters
- Name - Display name for the step. The step ID is derived from this name.
- Timeout - Maximum duration before the step times out. Default is
10m. - Container Registry - Select the container registry connector that Harness uses to pull the migration container.
- Select DB Schema - Choose the DB Schema associated with the instance you want to preview rollback SQL for.
- Select DB Instance - Choose the DB Instance against which the rollback SQL preview will be generated.
- Specify tag to rollback to - Choose how to identify the rollback target: rollback to a specific tag, or rollback by count. Go to Rollback for Database Schemas for details on each method.
Use the SQL output in downstream steps
The generated rollback SQL is available as a step output expression. Use this to pass the preview SQL into an approval gate or OPA policy step:
<+execution.steps.{stepGroupIdentifier}.steps.{stepIdentifier}.output.sqlCommands>
Next steps
- Go to Rollback DB Schema step to execute the rollback after validating the SQL.
- Go to Using OPA with Database DevOps to configure OPA policies that evaluate the generated SQL before rollback.