Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Platforms Launch Database Info

Jacqui Lough edited this page Mar 23, 2022 · 3 revisions

Some changes to the structure and content of the production Hasura instance are required to launch the new platforms version of the publishing stack. These can be accomplished through Hasura migrations, followed by metadata updates, as described below. Info on rolling back these changes in the event of a problem also follows.

Production Database Backup

I'm proposing we do two things to ensure we can always go back to the pre-Platforms version of the stack, even if something goes awry with migrations/metadata using the hasura cli:

  1. Hasura Postgres Database Dump: this is a special API request that can be found in our Postman collection. I have copied the curl version of the command below just in case.
curl --location --request POST 'https://tinynews-stack.hasura.app/v1alpha1/pg_dump' \
--header 'Content-Type: application/json' \
--header 'X-Hasura-Role: admin' \
--header 'x-hasura-admin-secret: <SECRET>' \
--data-raw '{
  "opts": ["-O", "-x", "-a", "--exclude-schema=hdb_catalog", "--inserts"],
  "clean_output": true,
  "source": "default"
}'

Hasura doesn't offer a straightforward way to apply this db dump - at least, not as far as I know - but I've done it by directly applying it through the psql command line.

  1. AWS RDS Snapshot: very simple to do through the RDS management console by clicking "Actions" dropdown then selecting "Take snapshot"

Migrations

hasura migrate apply --version 1644590978945 --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET>
hasura migrate apply --version 1644590996949 --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET>
hasura migrate apply --version 1645036768577 --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET>

Rollback

hasura migrate apply --version 1645036768577 --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET> --down 1
hasura migrate apply --version 1644590996949 --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET> --down 1
hasura migrate apply --version 1644590978945 --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET> --down 1

Rolling back the data will happen as a result of these down migrations, which will remove the settings table and the customDomain and subdomain columns from the organizations table.

Metadata

Once the metadata has been exported from the staging instance, run this command:

hasura metadata apply --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET>

It should apply without a problem. To double check, run this command to make sure there are no inconsistencies:

hasura metadata ic list --endpoint https://tinynews-stack.hasura.app/ --admin-secret <SECRET>

Data

After considering the options for populating the data, I have decided to use a mix of postgres export/import (settings table) and direct data entry in the Hasura console.

The settings table is straightforward and I've done two test runs of the task yesterday and today: export the settings data (csv) from postgres in staging directly; once the settings table is created in production (via migrations, above), import the same data (csv) into postgres directly. This works very nicely; all the organization_ids already match as staging was created as a replica of production.

The other data population task involves supplying the customDomain and subdomain values for the 6 tiny news orgs in the organizations table, which I'd prefer to do by hand. Writing the script seems riskier to me for this one-off, small change.

Once both of these are done, I can review the permissions and ensure all metadata is indeed applied right.

Clone this wiki locally