Skip to content

Instantly share code, notes, and snippets.

@timbophillips
Last active February 7, 2022 04:22
Show Gist options
  • Save timbophillips/cf330266a99a612f2cd7b3895438aa06 to your computer and use it in GitHub Desktop.
Save timbophillips/cf330266a99a612f2cd7b3895438aa06 to your computer and use it in GitHub Desktop.
Hasura Migration

My notes on migration

Only have to do this bit the first time

hasura init data-cli --endpoint http://localhost:8081 --admin-secret hello-this-is-my-admin-secret
cd data-cli/
hasura migrate create "init" --from-server --database-name default
hasura migrate apply --skip-execution --version <version-number-from-prev-migrate-command> --database-name default
hasura metadata export

Every other time start here

hasura console

now make the changes in the console...

hasura metadata export
hasura migrate status --database-name default

have a look... hopefull all migrations are present and present

hasura migrate squash --name "<make up a name>" --from <oldest version in above list> --database-name default

have a look... hopefull just one migration and should be Present | Not present

hasura migrate status --database-name default

this next line may fail if changes are already made (no stress)

hasura migrate apply --version <the new version name> --skip-execution --database-name default

have a look... hshould now be Present | Present

hasura migrate status --database-name default

Now make sure hasura imports the migrations at startup (in docker-compose.yaml ...)

...
    restart: always
        volumes:
     - ./<localtion relative to src>/migrations:/hasura-migrations
     - ./<localtion relative to src>/metadata:/hasura-metadata
    environment:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment