Skip to main content
Version: v2.x

Reset Hasura Migrations (config v2)

Introduction

This page explains how to reset the state of Migrations and create new Migrations from the state that is on the server. This can be useful if the current migration state on your local machine is corrupted.

Step 1: Delete the local migration files

Move all your Migrations to a backup folder, in case you may need them later.

You can use the following command:

# move the contents of the Migrations folder into the migrations_backup folder

mv migrations migrations_backup

Step 2: Reset the migration history on the server

On the SQL tab of the Hasura Console, run the following command:

TRUNCATE hdb_catalog.schema_migrations;

Step 3: Pull the schema and Metadata from the server

If the Migrations were reset, then we will set up fresh Migrations by pulling the schema and Metadata from the server using the following commands:

## create migration files - "this will only export public schema from postgres"

hasura migrate create "init" --from-server
## note down the version
## mark the migration as applied on this server

hasura migrate apply --version "<version>" --skip-execution
## to also export the Hasura Metadata and save it in the ``/metadata`` directory

hasura metadata export
Note

If you are using schemas other than public, use the --schema <schema_name> flag to indicate each one of them in the create command. This flag can be used multiple times.

Step 4: Verify the status of the Migrations

Run the following command to verify the migration status:

hasura migrate status

You should see the new Migrations!