Recommended approach before commit / deployment to staging:
yarn hasura:squash --name "migration_name" --from 1647464761013
where 1647464761013
is the version number (number at the beginning of the migration directory names).
Change the version at 3 locations (they should all match):
- docker-compose.yml, services > hasura > image
- db/hasura/Dockerfile
- the package
hasura-cli
in package.json (might be late in some cases - if that's your case, just use the latest available version)
Older approach to squash:
Update the schema with yarn schema
.
/!\ ATTENTION - only squash when all environments have the exact same version of the database schema: local, staging and production. If staging or prod is behind local, the diff won't be run on staging/prod which will result in an incomplete database schema (app bugs) and issues when running future migrations (schema requirements not fulfilled).
To squash the schema (merge all migration files into one single file), steps here. Beware: if the app is already deployed on multiple environments, it may prevent other environments from applying new migrations (unsynchronized migrations).
To apply squash to staging and prod, we need to clear the migration history in hasura database and mark the migration as already run (same as local for both).
(older?) alternative: hasura squash command (in preview). But it fails on migrations that don't have a down
filled with more than []
(e.g. when up
is a drop table
)
Connect Hasura to Google Cloud SQL through a UNIX socket
The database URL should look like:
postgres://dbusername:dbpassword@/dbname?host=/cloudsql/appid:zone:dbname
/cloudsql/appid:zone:dbname being provided by the database dashboard on Google Cloud
(source: https://dev.to/davidoliveira/setup-hasura-at-google-cloud-run-42i8 - search "And now the tricky part" on the page)