Resetting Hasura migrations

If you have too many migrations and want to squash them or your current migration state on the local machine is corrupted, you can reset the state and create new migrations from the state that is on the server.

Step 1: Nuke local migrations

Delete all the contents of your local migrations directory.

$ rm migrations/*

Step 2: Reset the migration history on server

On the SQL tab of console, execute the following statement:

TRUNCATE hdb_catalog.schema_migrations;

Step 3: Pull the schema and metadata from server

Setup fresh migrations by taking the schema and metadata from the server:

## (available after version alpha45)
## create migration files (note that 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

If you are using schemas other than public, use --schema "schema_name" flag to indicate each one of them in the create command. This flag can be used multiple times. See more details about the usage in the docs.

Step 4: Verify the status

Execute the following command to verify status of migration:

$ hasura migrate status

You have brand new migrations now!

This can also be used to combine (kind of squash) all of your migration files into a single one. You're snapshotting the state of a server and adding it as a new migration.

21 May, 2019
Subscribe to stay up-to-date on all things Hasura. One newsletter, once a month.
Accelerate development and data access with radically reduced complexity.