Anyone thought of connecting Hasura to Discourse's Postgres database for a potentially more customised (or narrowed down) FE?

For your information, to get a running psql shell of a running Discourse’s Postgres database server you can do docker exec --user postgres -it app psql -d discourse, so to get a full dump you can do (note, I am dropping -t option here as it is not needed in this case):

docker exec --user postgres -i app pg_dump -Fc -d discourse > discourse.sql.pgcustom

Should now be able to restore that to a dockerized postgres (docker pull postgres:10.12) and connect it to Hasura for development (only really useful at read-only level because it is a seperate database now).

To do this on production level, I would set the environment discourse provides and host your database in something like Amazon RDS. You then have easy access to read and write to that database.

To restore the dump above locally:

  1. Create a docker network:
docker network create discourse-dev-net
  1. In first shell:
docker run --rm -it -p 2345:5432 -e POSTGRES_DB=discourse -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres --name=discourse-dev-pg --network=discourse-dev-net postgres:10.12

(If you want it running in background, I think you can just replace -it for -d; -p 2345:5432 is optional but convenient if you want to connect to postgres from your host)

  1. In another shell, create discourse user in postgres (needed for dump):
docker run --rm -it -v /path/to/discourse.sql.pgcustom:/discourse.sql.pgcustom:ro -e PGPASSWORD=postgres --network=discourse-dev-net postgres:10.12 createuser -h discourse-dev-pg -U postgres -P discourse

(you then type password in prompt twice, I used discourse as password)

  1. Perform the restore:
docker run --rm -i -v /home/dean/Downloads/discourse.sql.pgcustom:/discourse.sql.pgcustom:ro -e PGPASSWORD=postgres --network=discourse-dev-net postgres:10.12 pg_restore -h discourse-dev-pg -U postgres -d discourse /discourse.sql.pgcustom
  1. To connect Hasura to the above:
docker run --rm -it --network=discourse-dev-net -p 1234:1234 -e HASURA_GRAPHQL_ENABLE_CONSOLE=true -e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:postgres@discourse-dev-pg:5432/discourse hasura/graphql-engine:v1.2.1 graphql-engine serve --server-port=1234

(You can now visit http://localhost:1234)