> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/database-devops/3.0/use-db-devops/deployment-pipeline-configuration/step-types/rollback-sql.md).

# Rollback SQL Step

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.

{% hint style="info" %}
The Rollback SQL step is a Liquibase-only step. It is not available for Flyway migrations.
{% endhint %}

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* **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](/database-devops/setup-db-devops/jdbc-connection-string/set-up-connectors.md) 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](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/using-rollback-tags.md) to learn how tags are created.

### Add the Rollback SQL step <a href="#add-the-rollback-sql-step" id="add-the-rollback-sql-step"></a>

1. In Harness, go to **Database DevOps** and select your project.
2. Open your pipeline and select the stage where you want to preview rollback SQL.
3. Select **Add Step** and choose **Rollback SQL**.
4. Configure the step parameters described below.
5. Select **Apply Changes**, then save and run the pipeline.

### Step parameters <a href="#step-parameters" id="step-parameters"></a>

1. **Name** - Display name for the step. The step ID is derived from this name.
2. **Timeout** - Maximum duration before the step times out. Default is `10m`.
3. **Container Registry** - Select the container registry connector that Harness uses to pull the migration container.
4. **Select DB Schema** - Choose the DB Schema associated with the instance you want to preview rollback SQL for.
5. **Select DB Instance** - Choose the DB Instance against which the rollback SQL preview will be generated.
6. **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](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/rollback-for-database-schemas.md) for details on each method.

### Use the SQL output in downstream steps <a href="#use-the-sql-output-in-downstream-steps" id="use-the-sql-output-in-downstream-steps"></a>

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 <a href="#next-steps" id="next-steps"></a>

* Go to [Rollback DB Schema step](/database-devops/use-db-devops/deployment-pipeline-configuration/step-types/rollback-dbschema-step.md) to execute the rollback after validating the SQL.
* Go to [Using OPA with Database DevOps](/database-devops/use-db-devops/governance-and-compliance/using-opa-with-database-devops.md) to configure OPA policies that evaluate the generated SQL before rollback.
