2020-01-14 15:57:45 +03:00
|
|
|
.. meta::
|
|
|
|
:description: Write manual migrations for Hasura GraphQL engine
|
|
|
|
:keywords: hasura, docs, migration, manual
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
.. _manual_migrations:
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
Writing migrations manually
|
|
|
|
===========================
|
|
|
|
|
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
Introduction
|
|
|
|
------------
|
|
|
|
|
|
|
|
While the Hasura console can auto generate migrations for every action,
|
2019-03-28 13:51:58 +03:00
|
|
|
sometimes you might want to write the migrations yourself, by hand. Using the
|
2019-09-11 10:17:14 +03:00
|
|
|
Hasura CLI, you can bootstrap these migration files and write the SQL for the
|
2020-04-29 11:00:26 +03:00
|
|
|
Postgres schema.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
For ``config v1``, see :ref:`manual_migrations_v1`.
|
|
|
|
|
|
|
|
Create migration manually
|
|
|
|
-------------------------
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
#. Set up the migration files:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
hasura migrate create <name-of-migration>
|
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
This command will create up and down migration SQL files in the
|
2019-03-28 13:51:58 +03:00
|
|
|
``migrations`` directory.
|
|
|
|
|
|
|
|
#. Edit the file and add your migration actions. For the file format and
|
|
|
|
instructions on what actions can be added, refer to
|
2020-04-29 11:00:26 +03:00
|
|
|
:ref:`migration file format <migration_file_format_v2>`.
|
|
|
|
|
|
|
|
#. The corresponding Hasura metadata changes, if any, can be made directly in
|
|
|
|
the appropriate metadata file in the ``/metadata`` directory, refer to
|
|
|
|
:ref:`metadata format <metadata_format_v2>`.
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2020-04-29 11:00:26 +03:00
|
|
|
#. Apply the migration and metadata:
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
hasura migrate apply
|
2020-04-29 11:00:26 +03:00
|
|
|
hasura metadata apply
|