2020-01-14 15:57:45 +03:00
|
|
|
.. meta::
|
|
|
|
:description: Roll back Hasura migrations
|
|
|
|
:keywords: hasura, docs, migration, roll back
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
.. _roll_back_migrations:
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
Rolling back applied migrations
|
|
|
|
===============================
|
|
|
|
|
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
Introduction
|
|
|
|
------------
|
|
|
|
|
|
|
|
If there are any issues with changes made to the DB schema and Hasura metadata it
|
|
|
|
is possible to roll back their state to a previous stable version.
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
For ``config v1``, see :ref:`roll_back_migrations_v1`.
|
|
|
|
|
|
|
|
Rolling back database schema
|
|
|
|
----------------------------
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
Database schema rollbacks can be achieved via the ``down`` migrations generated
|
|
|
|
every time a schema change is made.
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
Here are some example scenarios:
|
|
|
|
|
|
|
|
To roll back a particular migration version:
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2021-03-11 11:12:27 +03:00
|
|
|
hasura migrate apply --version 1550925483858 --type down --database-name <database-name>
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
To roll back the last 2 migration versions:
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2021-03-11 11:12:27 +03:00
|
|
|
hasura migrate apply --down 2 --database-name <database-name>
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Rollbacks will only work if there are ``down`` migrations defined for a
|
|
|
|
schema change.
|
|
|
|
|
|
|
|
e.g. The console will not generate ``down`` migrations for SQL statements
|
|
|
|
executed from the ``SQL`` tab.
|
|
|
|
|
|
|
|
Rolling back Hasura metadata
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
As Hasura metadata is managed via snapshots of the metadata, to roll back
|
|
|
|
Hasura metadata to a particular state you need the metadata snapshot at that
|
|
|
|
point. This is typically achieved by marking stable checkpoints of a project in
|
|
|
|
version control via commits.
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
git checkout <stable-feature-commit>
|
|
|
|
|
|
|
|
hasura metadata apply
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
|