2020-04-29 11:00:26 +03:00
|
|
|
|
.. meta::
|
|
|
|
|
:description: Auto-apply migrations and metadata when the server starts
|
|
|
|
|
:keywords: hasura, docs, auto-apply, migration, metadata, server
|
|
|
|
|
|
|
|
|
|
.. _auto_apply_migrations:
|
|
|
|
|
|
|
|
|
|
Auto-apply migrations/metadata when the server starts
|
|
|
|
|
=====================================================
|
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
.. contents:: Table of contents
|
|
|
|
|
:backlinks: none
|
|
|
|
|
:depth: 1
|
|
|
|
|
:local:
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
**cli-migrations** image
|
|
|
|
|
------------------------
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
Hasura ships a special Docker image which can be used to
|
|
|
|
|
automatically apply migrations/metadata when the server starts:
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
.. code-block:: bash
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
hasura/graphql-engine:<version>.cli-migrations-v3
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
This container image includes the Hasura CLI at ``/bin/hasura-cli`` and can be
|
|
|
|
|
used for running any other CI/CD scripts in your workflow.
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
.. note::
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
For ``config v2``, see :ref:`auto_apply_migrations_v2`.
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
Applying migrations
|
|
|
|
|
-------------------
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
The ``migrations`` and ``metadata`` directories created by the Hasura CLI in a
|
|
|
|
|
Hasura project can be mounted at the ``/hasura-migrations`` and ``/hasura-metadata``
|
|
|
|
|
path of this Docker container and the container's entry point script will apply the
|
|
|
|
|
migrations and metadata before starting the server. If no directory is mounted at
|
|
|
|
|
the designated paths, the server will start ignoring the migrations and/or metadata.
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
If you want to mount the migrations/metadata directories at some location other
|
|
|
|
|
than the above, set the following environment variables:
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
.. code-block:: bash
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
HASURA_GRAPHQL_MIGRATIONS_DIR=/custom-path-for-migrations
|
|
|
|
|
HASURA_GRAPHQL_METADATA_DIR=/custom-path-for-metadata
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
Once the migrations and metadata are applied, the container resumes operation as
|
|
|
|
|
a normal Hasura GraphQL engine server.
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
Example:
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
.. code-block:: bash
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
# Start Hasura after applying the migrations and metadata present in the Hasura project
|
|
|
|
|
docker run -p 8080:8080 \
|
|
|
|
|
-v /home/me/my-project/migrations:/hasura-migrations \
|
|
|
|
|
-v /home/me/my-project/metadata:/hasura-metadata \
|
|
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:@postgres:5432/postgres \
|
2021-09-16 12:38:14 +03:00
|
|
|
|
hasura/graphql-engine:<version>.cli-migrations-v3
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
.. _auto_apply_metadata:
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
Applying only metadata
|
|
|
|
|
----------------------
|
2020-04-29 11:00:26 +03:00
|
|
|
|
|
2021-04-06 12:58:24 +03:00
|
|
|
|
If you're managing migrations with a different tool and want to use this image
|
|
|
|
|
to apply only the metadata, mount the ``metadata`` directory of your Hasura project
|
|
|
|
|
at the ``/hasura-metadata`` path of this Docker container the container’s entry point
|
|
|
|
|
script will apply the metadata before starting the server.
|
2021-03-09 11:36:02 +03:00
|
|
|
|
|