> 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/use-db-devops/deployment-pipeline-configuration/step-types/rollback-dbschema-step.md).

# Rollback DB Schema step

Configure the Rollback DB Schema step in a Harness Database DevOps pipeline to revert Liquibase or Flyway migrations to a specific tag, by a changeset count, or by a specific changeset

The **Rollback DB Schema** step reverts previously applied database changesets on a target DB instance as part of a Harness pipeline. It is typically added after an [Apply DB Schema step](/database-devops/use-db-devops/deployment-pipeline-configuration/step-types/apply-dbschema-step.md) as part of a failure strategy or a dedicated rollback stage.

***

## Before you begin

Ensure the following conditions are met before adding this step to your pipeline.

* **Applied migrations:** Rollback requires changesets previously applied by an Apply DB Schema step. Nothing can be rolled back on a fresh instance with no applied changesets.
* **Rollback scripts:** Liquibase rollback requires that each changeset defines a rollback statement. Go to [Automatic and custom rollbacks](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/automatic-and-custom-rollback.md) for when rollback scripts are required.
* **Tag (for rollback by tag):** The target tag must exist in `DATABASECHANGELOG`. Go to [Use rollback tags with Apply Schema step](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/using-rollback-tags.md) for how tags are created.
* **Fully qualified changeset identity (for rollback of a specific changeset):** You need the file path, changeset id, and author in the form `<file-path-of-changeset>::<changeset-id>::<changeset-author>`. Go to [Automated rollback for database schemas](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/rollback-for-database-schemas.md) for the format, warning, and limitations.
* **Pipeline permissions:** You need permission to create and edit pipelines in the project. Go to [RBAC in Harness](https://developer.harness.io/docs/platform/role-based-access-control/rbac-in-harness) to configure roles.

***

### Add the Rollback DB Schema step

1. In Harness, go to **Database DevOps** and select your project.
2. Open your pipeline and select the stage where you want to configure rollback.
3. Add a **Custom Stage** with a step group.
4. Inside the step group, click **Add Step** and choose **Rollback DB Schema**.
5. Configure the step parameters described below.
6. Click **Apply Changes**, then save and run the pipeline.

### Step parameters

![Rollback DB Schema step configuration showing name, timeout, migration type, DB Schema, DB Instance, and Specify tag to rollback to options](https://4089095456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWwqb27iUU3gZvwGNroZp%2Fuploads%2Fgit-blob-d73e439cdcfe0655cd5b4e696a2dd708999d9bb2%2Fdbops-rollback-schema-step.png?alt=media)

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. **Migration Type** - Select **Liquibase** or **Flyway** depending on your schema's migration tool.
5. **Select DB Schema** - Choose the DB Schema associated with the instance you want to roll back.
6. **Select DB Instance** - Choose the DB Instance where the rollback will be executed.
7. **Specify tag to rollback to** - Choose how to identify the rollback target: rollback to a specific tag, rollback by count, rollback a specific changeset, or rollback to a target version (Flyway). Select exactly one mode. When you select **Rollback a specific changeset**, enter the value in the form `<file-path-of-changeset>::<changeset-id>::<changeset-author>` (for example, `sample.changelog.yaml::9::dbe_team`). Go to [Automated rollback for database schemas](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/rollback-for-database-schemas.md) for the sample changelog, FQN examples, and YAML for `changesetFQN`.

{% hint style="warning" %}
**Rollback a specific changeset**

Warning: rolling back changesets out of order can result in your database being left in an inconsistent state and is not recommended
{% endhint %}

***

## Troubleshooting

<details>

<summary>Rollback fails with tag not found</summary>

Verify the specified tag exists in the `DATABASECHANGELOG` table. Check that the Apply DB Schema step created the tag successfully. Use `SELECT * FROM DATABASECHANGELOG WHERE TAG IS NOT NULL` to list available tags.

</details>

<details>

<summary>No rollback script defined error</summary>

For Liquibase changesets, ensure each changeset includes a rollback block. Some change types support automatic rollback, but custom SQL requires explicit rollback statements. Go to [Automatic and custom rollbacks](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/automatic-and-custom-rollback.md) for rollback script patterns.

</details>

<details>

<summary>Rollback step times out</summary>

Increase the timeout value in the step configuration. Check for database locks that prevent rollback execution. Verify the rollback operations are not blocked by foreign key constraints or triggers.

</details>

<details>

<summary>Rollback count exceeds available changesets</summary>

The rollback count parameter specifies how many changesets to roll back from the current state. Verify the count does not exceed the total number of applied changesets. Check the `DATABASECHANGELOG` table to see how many changesets are recorded.

</details>

<details>

<summary>Specific-changeset rollback fails</summary>

Confirm the fully qualified identity uses three non-empty parts separated by `::`. Verify the file path, id, and author match the applied changeset. If a later tag-based rollback fails after this step, the rolled-back row may have held the tag. Go to [Automated rollback for database schemas](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/rollback-for-database-schemas.md) for that limitation.

</details>

***

## Next steps

The following resources provide information about database rollback strategies and configuration:

* Go to [Apply DB Schema step](/database-devops/use-db-devops/deployment-pipeline-configuration/step-types/apply-dbschema-step.md) to configure the apply step that precedes rollback.
* Go to [Automated rollback for database schemas](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/rollback-for-database-schemas.md) to review rollback methods, automated rollback patterns, and failure strategies.
* Go to [Automatic and custom rollbacks](/database-devops/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/automatic-and-custom-rollback.md) to write rollback scripts for complex changesets.

{% @harness-feedback/feedback %}
