restoreTable

restoreTable is a Change Type in the Liquibase Pro Databricks extension that restores a table to an earlier state. It is available in the Liquibase Pro Databricks extension 1.0.0 and later.

Uses

You can use this change to restore an existing Databricks table to an earlier state. This is useful if you need to recover from accidental data deletion or corruption or if you need to access a specific table version to reproduce and understand previous behavior.

For more information, see Databricks SQL Reference: RESTORE.

You can restore a specific instance of the table using either its Databricks commit version or associated timestamp. For more information, see Work with Delta Lake table history.

Run restoreTable

To run this Change Type, follow these steps:

  1. Add the Change Type to your changeset, as shown in the examples on this page.
  2. Specify any required attributes. Use the table on this page to see which ones your database requires.
  3. Deploy your changeset by running the update command:
  4. liquibase update

Available attributes

Tip: You must specify all top-level attributes marked as required. If you specify an optional attribute, you must also specify any nested attributes that it requires.

Name Type Description Requirement
tableName String Name of the table to restore to an earlier version Required
asOfDate String

Whenever you modify your table, Databricks captures different states of the table in a "commit," which includes a timestamp. You can use this attribute to specify the timestamp representing the state of your table. For example, you can specify 2025-01-01 or 2022-08-02 00:00:00. For more information, see Work with Delta Lake table history.

Optional
asOfVersion Integer

Whenever you modify your table, Databricks captures different states of the table in a "commit," which includes a version number. You can use this attribute to specify the version of your table. For example, you can specify 1 or 15. For more information, see Work with Delta Lake table history.

Optional
catalogName String

Name of the catalog containing the table to restore to an earlier version

Optional
schemaName String

Name of the schema containing the table to restore to an earlier version

Optional

Examples

For example, imagine you have created a table called restoreTable_example (version 0). In a later change, you added the column test_column (version 1). However, you now want to restore the table to its original state (with no columns). The following syntax shows the restoreTable syntax for this use-case.

Note: Liquibase cannot generate an automatic rollback for this change, so you must specify one manually. The Liquibase rollback clause represents the inverse of the restore change, so in this case re-adding the column. For a different use-case, you must specify a different or empty rollback.

databaseChangeLog:
  - changeSet:
      id: 3
      author: your.name
      changes:
        - restoreTable:
            tableName: restoreTable_example
            asOfVersion: 0
      rollback:
        - addColumn:
            tableName: restoreTable_example
            columns:
              column:
                columnName: test_column
                type: string
{
  "databaseChangeLog": [
    {
      "changeSet": {
        "id": "3",
        "author": "your.name",
        "changes": [
          {
            "restoreTable": {
              "tableName": "restoreTable_example",
              "asOfVersion": "0"
            }
          }
        ],
        "rollback": [
          {
            "addColumn": {
              "tableName": "restoreTable_example",
              "columns": [
                {
                  "column": {
                    "columnName": "test_column",
                    "type": "string"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:databricks="http://www.liquibase.org/xml/ns/databricks"
    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/databricks
        http://www.liquibase.org/xml/ns/databricks/liquibase-databricks-latest.xsd
        http://www.liquibase.org/xml/ns/pro
        http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">

    <changeSet id="3" author="your.name">
        <pro-databricks:restoreTable tableName="restoreTable_example" asOfVersion="0"/>

        <rollback>
            <addColumn tableName="restoreTable_example">
                <column name="test_column" type="string">
            </addColumn>
        </rollback>
    </changeSet>
</databaseChangeLog>

Database support

This Change Type is only supported for Databricks. It does not support auto rollback.

Related links