2020-01-14 15:57:45 +03:00
|
|
|
.. meta::
|
|
|
|
:description: Manage Hasura migrations and metadata
|
|
|
|
:keywords: hasura, docs, migration, metadata
|
|
|
|
|
2018-09-11 14:11:24 +03:00
|
|
|
.. _migrations:
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
Migrations & Metadata
|
|
|
|
=====================
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
2020-04-29 11:00:26 +03:00
|
|
|
:depth: 2
|
2018-12-03 15:12:24 +03:00
|
|
|
:local:
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
Introduction
|
|
|
|
------------
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
It is a typical requirement to export an existing Hasura "setup" so that you can
|
|
|
|
apply it on another instance to reproduce the same setup. For example, to achieve
|
|
|
|
a dev -> staging -> production environment promotion scenario.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2021-02-23 18:34:38 +03:00
|
|
|
This documentation is for Hasura migrations ``config v3``, supported from
|
2021-03-04 22:20:19 +03:00
|
|
|
``v2.0.0-alpha.1``. (See :ref:`upgrade guide <migrations_upgrade_v3>`).
|
2020-04-29 11:00:26 +03:00
|
|
|
|
2021-02-23 18:34:38 +03:00
|
|
|
For ``config v2``, see :ref:`migrations_v2`.
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
|
|
How is Hasura state managed?
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
Hasura needs 2 pieces of information to recreate your GraphQL API, the underlying
|
|
|
|
PG database schema and the Hasura metadata which is used to describe the exposed
|
|
|
|
GraphQL API.
|
|
|
|
|
2020-07-09 03:26:26 +03:00
|
|
|
The :ref:`Hasura CLI <hasuracli_manual>` lets you manage these pieces of
|
2020-04-29 11:00:26 +03:00
|
|
|
information as you build your project via:
|
|
|
|
|
|
|
|
Database migration files
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
The state of your PG database is managed via incremental SQL migration files.
|
|
|
|
These migration files can be applied one after the other to achieve the final
|
|
|
|
DB schema.
|
|
|
|
|
|
|
|
DB migration files can be generated incrementally and can by applied in parts to
|
|
|
|
reach particular checkpoints. They can be used to roll-back the DB schema as well.
|
|
|
|
|
2020-09-08 23:14:36 +03:00
|
|
|
.. note::
|
|
|
|
|
2020-09-10 12:32:57 +03:00
|
|
|
You can choose to manage database migrations using external tools like knex, TypeORM,
|
|
|
|
Django/Rails migrations, etc. as well.
|
2020-09-08 23:14:36 +03:00
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
Hasura metadata files
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
The state of Hasura metadata is managed via snapshots of the metadata. These
|
|
|
|
snapshots can be applied as a whole to configure Hasura to a state represented
|
|
|
|
in the snapshot.
|
|
|
|
|
|
|
|
Hasura metadata can be exported and imported as a whole.
|
|
|
|
|
|
|
|
Setting up migrations
|
|
|
|
---------------------
|
|
|
|
|
2020-09-08 23:14:36 +03:00
|
|
|
See :ref:`migrations_setup`.
|
2020-04-29 11:00:26 +03:00
|
|
|
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
Advanced use cases
|
|
|
|
------------------
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
- :ref:`auto_apply_migrations`
|
|
|
|
- :ref:`manual_migrations`
|
|
|
|
- :ref:`roll_back_migrations`
|
2020-04-29 11:00:26 +03:00
|
|
|
- :ref:`seed_data_migration`
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
Reference documentation
|
|
|
|
-----------------------
|
2018-11-02 17:08:25 +03:00
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
- :ref:`migrations_how_it_works`
|
2021-02-24 15:30:34 +03:00
|
|
|
- :ref:`Migration file format <migration_file_format>`
|
|
|
|
- :ref:`Metadata format <metadata_format>`
|
2018-11-02 17:08:25 +03:00
|
|
|
|
2018-09-11 14:11:24 +03:00
|
|
|
.. toctree::
|
2021-03-08 18:42:35 +03:00
|
|
|
:maxdepth: 10
|
2019-03-28 13:51:58 +03:00
|
|
|
:hidden:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-06-11 13:14:04 +03:00
|
|
|
Setting up migrations <migrations-setup>
|
|
|
|
Managing metadata <manage-metadata>
|
2019-03-28 13:51:58 +03:00
|
|
|
Advanced use cases <advanced/index>
|
|
|
|
Reference documentation <reference/index>
|
2021-02-23 18:34:38 +03:00
|
|
|
Upgrading to config v3 <upgrade-v3>
|
|
|
|
Config v2 <config-v2/index>
|
2020-04-29 11:00:26 +03:00
|
|
|
Config v1 <config-v1/index>
|
2021-03-09 11:36:02 +03:00
|
|
|
|