Local DB Setup Guide
For anyone who is working on or branching off FREE-90, here are the steps to get the DB running locally so you can use our new data. Hopefully this won’t be needed soon because our new data will be deployed.
Install Docker Desktop
Follow installation steps here: https://docs.docker.com/get-docker/
Set Up Hasura and Postgres
Clone this repo: https://github.com/Rayahhhmed/hasuragres
In the root directory of this repo run (this may take a long time)
docker compose up -d
Once that’s done you should be able to navigate to http://localhost:8080/console/ and see something like:
Create the Database
On the Hasura console page go to the “Data” tab
Press the “Connect Database” button and select “Postgres”
Name it whatever you want, and connect by the following Database URL:
postgres://postgres:postgrespassword@postgres:5432/postgres
There should now be a new database on the left sidebar, as well as an “SQL” tab (might need to refresh)
Go to the SQL tab and run the SQL from this file: https://github.com/Rayahhhmed/hasuragres/blob/master/db_dump/RoomBookings.sql - make sure the “Track this” option is ticked
There should now be a bunch of tables in your sidebar:
Go to the “public” schema (folder icon) on the left and click the “Track All” button next to the “Untracked foreign-key relationships” section
Run the Scraper
Clone the following repo: https://github.com/csesoc/nss-scraper
In the root directory of this repo run (you will get warnings about no pattern found, ignore them)
npm install && npm run scrape
There should now be a bunch of JSON files in the output directory:
Install psycopg2
Install Python3 if you haven’t already for some reason
Install the Python package
psycopg2
, for example using
pip3 install psycopg2
Mac users might need to follow these steps (they assume you have Homebrew installed)
Insert Data into Postgres
Create a file in the root directory of
nss-scraper
calledinsert_data.py
with the following contents:
In the root directory of
nss-scraper
run
python3 insert_data.py
When it finishes, the tables on the Hasura console should now be populated with data:
Ready to Go
Should be good to run the backend and frontend as normal now
To run the database again in future, just open Docker Desktop and run the hasuragres container from the dashboard