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.
Make sure you have the Nhost CLI installed.
nhost init my-nhost-v2-app
cd my-nhost-v2-app
Update 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.
Inside the 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 nhost/migrations/[timestamp]/up.sql
.
Add OR REPLACE
after CREATE
for the public.set_current_timestamp_updated_at
function
Delete all auth.*
tables and functions (if any).
Delete public.users
table and everything related to the table such as constraints, triggers, etc.
Update FK references from public.users
to auth.users
(if any).
Make the following changes manually to your metadata.
The metadata is located at nhost/metadata/tables.yaml
.
Delete tracking all tables in the auth
schema.
Delete tracking the public.users
table.
Update all references to users
from the public
to auth
schema.
Start Nhost locally using the CLI. From the root of your app, run:
nhost -d
Running nhost -d
applies your local database migrations and Hasura metadata.
Open Docker UI and restart Hasura Auth and Hasura Storage. Restarting those containers applies new metadata, effectively tracking everything in the auth
and the storage
schema.
Delete the local migrations and metadata.
rm -rf nhost/migrations nhost/metadata
Update config: 2
to config: 3
in nhost/config.yaml
.
In the 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.
We use cookies to provide our services and for analytics and marketing. By continuing to browse our website, you agree to our use of cookies.
To find out more about our use of cookies, please see our Privacy Policy and Cookies Policy.