Skip to content

Instantly share code, notes, and snippets.

@MattMacGillivray
Last active June 24, 2020 17:35
Show Gist options
  • Save MattMacGillivray/dbf039d743d2e34518d29ca8dc69b7e1 to your computer and use it in GitHub Desktop.
Save MattMacGillivray/dbf039d743d2e34518d29ca8dc69b7e1 to your computer and use it in GitHub Desktop.
hasura migrate and schema management example
mattm$ pwd
/Users/mattm/dev/project1/hasura
# i have migrations that i've generated from dev, that i want to apply to staging/prod
mattm$ ls
config.yaml metadata migrations
# dev and prod both have the console DISABLED
# you run the console locally, and connect to dev/prod
# connect to local dev with the console - to make sure you can connect for the migrate command
mattm$ hasura console --admin-secret <secret> --endpoint http://localhost:8080
INFO console running at: http://localhost:9695/
^C
# connect to production with the console - to make sure you can connect for the migrate command
mattm$ hasura console --admin-secret <secret> --endpoint https://production-url.heroku.com
INFO console running at: http://localhost:9695/
^C
# view migrations on local dev
mattm$ hasura migrate status --admin-secret <secret> --endpoint http://localhost:8080
VERSION NAME SOURCE STATUS DATABASE STATUS
1592933468449 example_migration1 Present Present
1592933870203 example_migration2 Present Present
# view migrations on production
mattm$ hasura migrate status --admin-secret <secret> --endpoint https://production-url.heroku.com
VERSION NAME SOURCE STATUS DATABASE STATUS
1592933468449 example_migration1 Present Not Present
1592933870203 example_migration2 Present Not Present
# migrations were "not present" thus haven't been applied on production yet
# apply them
mattm$ hasura migrate apply --admin-secret <secret> --endpoint https://production-url.heroku.com
INFO migrations applied
# check the status
mattm$ hasura migrate status --admin-secret <secret> --endpoint https://production-url.heroku.com
VERSION NAME SOURCE STATUS DATABASE STATUS
1592933468449 example_migration1 Present Present
1592933870203 example_migration2 Present Present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment