|
| 1 | +.. meta:: |
| 2 | + :description: Upgrading to Hasura GraphQL engine v2 |
| 3 | + :keywords: hasura, docs, guide, compatibility |
| 4 | + |
| 5 | +.. _upgrade_hasura_v2: |
| 6 | + |
| 7 | +Upgrading to Hasura GraphQL engine v2 |
| 8 | +===================================== |
| 9 | + |
| 10 | +.. contents:: Table of contents |
| 11 | + :backlinks: none |
| 12 | + :depth: 2 |
| 13 | + :local: |
| 14 | + |
| 15 | +Introduction |
| 16 | +------------ |
| 17 | + |
| 18 | +This page talks about the conceptual changes introduces in Hasura v2 and things to |
| 19 | +keep in mind while upgrading from Hasura v1 to v2. |
| 20 | + |
| 21 | +Do reach out to us if you run into any issues while using Hasura v2 or have any questions |
| 22 | +regarding any changes introduced. |
| 23 | + |
| 24 | +What has changed? |
| 25 | +----------------- |
| 26 | + |
| 27 | +Concepts |
| 28 | +^^^^^^^^ |
| 29 | + |
| 30 | +The following are the most significant conceptual changes introduced in Hasura v2: |
| 31 | + |
| 32 | +- Hasura v2 can now connect to multiple databases to generate a unified GraphQL API. Each connected |
| 33 | + database will have a unique "source name" that is used to identify it. Apart from Postgres, connecting to |
| 34 | + SQL server databases is also now supported. |
| 35 | + |
| 36 | +- Config for connecting a database used to be a startup configuration (i.e. set via env vars/flags) |
| 37 | + but since v2, it is a part of Hasura metadata and can be managed dynamically. |
| 38 | + See :ref:`connecting databases <connect_database>`. |
| 39 | + |
| 40 | +- Hasura metadata can now be stored in a separate dedicated Postgres DB. |
| 41 | + |
| 42 | +.. note:: |
| 43 | + |
| 44 | + A detailed changelog with all the new features introduced in Hasura v2 is available on the |
| 45 | + `releases page <https://github.com/hasura/graphql-engine/releases>`__. |
| 46 | + |
| 47 | +Hasura configuration |
| 48 | +^^^^^^^^^^^^^^^^^^^^ |
| 49 | + |
| 50 | +- To accommodate changes for storing information for multiple databases, the Hasura metadata and |
| 51 | + the Hasura CLI project versions have been bumped from ``v2`` to ``v3``. The ``v2`` versions of the |
| 52 | + metadata and CLI project can continue to be used with Hasura v2 instances. Hasura v2 will assume the |
| 53 | + ``v2`` metadata and migrations belong to a database connected with the name ``default``. |
| 54 | + |
| 55 | +- A new optional env var ``HASURA_GRAPHQL_METADATA_DATABASE_URL`` is now introduced. When set, this |
| 56 | + Postgres database is used to store the Hasura metadata. If not set, the database set using |
| 57 | + ``HASURA_GRAPHQL_DATABASE_URL`` is used to store the Hasura metadata. |
| 58 | + |
| 59 | + Either one of ``HASURA_GRAPHQL_METADATA_DATABASE_URL`` or ``HASURA_GRAPHQL_DATABASE_URL`` needs to be set |
| 60 | + with a Postgres database to start a Hasura v2 instance as Hasura always needs a Postgres database to store |
| 61 | + its metadata. |
| 62 | + |
| 63 | +- ``HASURA_GRAPHQL_DATABASE_URL`` env var works in a backwards compatible way. The database set using this env var is |
| 64 | + connected automatically with the name ``default`` in Hasura v2 while upgrading an existing instance or while starting a fresh |
| 65 | + instance. |
| 66 | + |
| 67 | + Setting this env var post startup/upgrade will have no effect as the Hasura metadata would already have been initalized and the |
| 68 | + env var will be treated as any other custom env var. |
| 69 | + |
| 70 | + It is now not mandatory to set this env var if a dedicated ``HASURA_GRAPHQL_METADATA_DATABASE_URL`` is set. |
| 71 | + |
| 72 | +- The values of the env vars ``HASURA_GRAPHQL_PG_CONNECTIONS``, ``HASURA_GRAPHQL_PG_TIMEOUT`` and ``HASURA_GRAPHQL_NO_OF_RETRIES`` |
| 73 | + are used to define the connection parameters of the ``default`` database while upgrading an existing instance or while starting a fresh |
| 74 | + instance. |
| 75 | + |
| 76 | + Changing or setting values of these env vars post startup/upgrade will have no impact as their initial values would have been moved to |
| 77 | + the Hasura metadata already and the values there are now used to define the connection parameters. |
| 78 | + |
| 79 | +- Custom env vars can now be used to connect databases dynamically at runtime. |
| 80 | + |
| 81 | +Hasura Cloud |
| 82 | +^^^^^^^^^^^^ |
| 83 | + |
| 84 | +Hasura Cloud projects' metadata is now stored in metadata DBs managed by Hasura Cloud. Hence |
| 85 | +the ``HASURA_GRAPHQL_METADATA_DATABASE_URL`` env var is not configurable on Hasura Cloud and is managed |
| 86 | +by Hasura Cloud itself. |
| 87 | + |
| 88 | +By default Hasura Cloud projects are created without any databases connected to them. See :ref:`connecting databases <connect_database>` to add a database |
| 89 | +to a Hasura Cloud v2 project. |
| 90 | + |
| 91 | +See the below section on :ref:`hasura_v1_v2_compatibility` to use a Hasura v2 Cloud project like a Hasura v1 |
| 92 | +Cloud project. |
| 93 | + |
| 94 | +Moving from Hasura v1 to Hasura v2 |
| 95 | +---------------------------------- |
| 96 | + |
| 97 | +.. _hasura_v1_v2_compatibility: |
| 98 | + |
| 99 | +Hasura v1 and Hasura v2 compatibility |
| 100 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 101 | + |
| 102 | +All existing metadata and migrations from a Hasura v1 instance are assumed to belong to a database named ``default`` in |
| 103 | +Hasura v2. |
| 104 | + |
| 105 | +Hence **in Hasura v2, a database with name "default" needs to be added to apply metadata and migrations from a |
| 106 | +Hasura v1 instance**. |
| 107 | + |
| 108 | +Post adding a database named ``default``, the Hasura v2 instance should behave equivalently to the Hasura |
| 109 | +v1 instance and all previous workflows will continue working as they were. |
| 110 | + |
| 111 | +Refer to :ref:`connecting databases <connect_database>` to add a database to Hasura v2. |
| 112 | + |
| 113 | + |
| 114 | +Migrate Hasura v1 instance to Hasura v2 |
| 115 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 116 | + |
| 117 | +Hasura v2 is backwards compatible with Hasura v1. Hence simply updating the Hasura docker image version number |
| 118 | +and restarting your Hasura instance should work seamlessly. The database connected using the ``HASURA_GRAPHQL_DATABASE_URL`` |
| 119 | +env var will be added as a database with the name ``default`` automatically and all existing metadata and migrations will be |
| 120 | +run against it. |
| 121 | + |
| 122 | +Upgrade CLI project to enable multiple database support |
| 123 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 124 | + |
| 125 | +Update your Hasura CLI project to ``config v3`` using the steps mentioned in :ref:`this guide <migrations_upgrade_v3>` |
| 126 | +to take full advantages of the features introduced in Hasura v2. |
| 127 | + |
| 128 | +.. note:: |
| 129 | + |
| 130 | + If you do not need multiple database support then you can continue to use ``config v2`` project directory and workflows. |
| 131 | + |
| 132 | + Though we would recommend to upgrade to ``config v3`` anyway as it includes some useful directory structure changes. |
| 133 | + |
| 134 | +Updates to CI/CD after upgrading to Hasura v2 |
| 135 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 136 | + |
| 137 | +- Ensure the same env vars are used to store the database urls across different environments. |
| 138 | + |
| 139 | +- If using Hasura CLI project in ``config v3``: |
| 140 | + |
| 141 | + Run ``hasura metadata apply`` first and then ``hasura migrate apply``. |
| 142 | + |
| 143 | +- If using Hasura CLI project in ``config v2``: |
| 144 | + |
| 145 | + No changes needed. Run ``hasura migrate apply`` first and then ``hasura metadata apply``. |
0 commit comments