Migrate from Nhost v1 to v216 January 2022
This is a guide that explains how to migrate a project from Nhost v1 to Nhost v2.
Upgrading from Nhost v1 to v2 requires database schema and Hasura metadata changes.
Create a new Nhost v2 app locally
Make sure you have the Nhost CLI installed.
nhost init my-nhost-v2-app cd my-nhost-v2-app
version: 3 to
version: 2 in
nhost/config.yaml. This will update Hasura's configuration version, and we need to downgrade the version when we export migrations and metadata.
Export current migrations and metadata from Nhost v1
nhost/ folder of your app, run:
hasura migrate create init --from-server --endpoint=[v1-endpoint] --admin-secret=[v1-admin-secret] hasura metadata export --endpoint=[v1-endpoint] --admin-secret=[v1-admin-secret]
Make the following changes manually to your migrations.
The migration file is located at
- Delete all
auth.*tables and functions (if any).
public.userstable and everything related to the table such as constraints, triggers, etc.
- Update FK references from
Make the following changes manually to your metadata.
The metadata is located at
- Delete tracking all tables in the
- Delete tracking the
- Update all references to
Start Nhost locally using the CLI. From the root of your app, run:
nhost -d applies your local database migrations and Hasura metadata.
Restart Auth and Storage Containers
Open Docker UI and restart Hasura Auth and Hasura Storage. Restarting those containers applies new metadata, effectively tracking everything in the
auth and the
Delete Migrations and Metadata
Delete the local migrations and metadata.
rm -rf nhost/migrations nhost/metadata
Update Config (again)
config: 2 to
config: 3 in
Pull Migrations and Metadata from the Local Instance
nhost/ folder, run the following command:
hasura migrate create init --from-server --endpoint=http://localhost:[hasura-port] --admin-secret=nhost-admin-secret hasura metadata export --endpoint=http://localhost:[hasura-port] --admin-secret=nhost-admin-secret
Note: You cannot use port
1337 in the commands above. You have to use the specific port Hasura uses. Go to the Hasura Console under API and look for the port Hasura is using under GraphQL Endpoint.
You now have a Nhost v2 project locally with correct migrations and metadata.
To fully migrate, you need to transfer data from v1 to v2. This can be done in three steps:
- Read data from v1
- Modify data so it can be imported to v2
- Write data to v2
You can also use TransferGraph, an open source tool from the community that helps you do this.