- Install Yarn (Required):
> brew install yarn
- Optionally install nvm and avn to automatically switch node versions.
- Install Docker and Docker Compose
- Docker Desktop is the simplest solution and includes both Docker and Docker Compose.
- Install Hasura CLI
- NPM is the simplest
way to get the
hasuracommand. You'll need to install it globally since the backend services are currently not NodeJS projects.
There are two options for developing the app.
- Develop against the mock data server. In this setup, all API requests are dynamically mocked by the front end and you don't need to connect to Docker or any live services.
- Develop against a locally running backed. In this setup you will run the GraphQL APIs locally with Docker and point the app towards those APIs.
> cd react-frontend
> yarn start-mock
This will start the development server using mock APIs based on our GraphQL
schema. If you need to make any changes to the GraphQL schema during
development, you will need to switch to running the local GraphQL environment,
make your changes, download the schema into the frontend project and then you
can go back to developing against the mocks. For more information, see the
documentation in the react-frontend project.
> docker compose up -d
> cd react-frontend
> yarn start
This will start the Docker environment with a local Postgres DB and Hasura GraphQL API and will run the frontend project against the APIs running in Docker.
Our backend is run using docker compose which will start up Hasura and Postgres for you.
> docker compose up -d
Be aware that you will need to shut down docker manually when you are finished with your development.
You can connect to the Hasura Console via Hasura CLI to verify the metadata and migrations were applied.
To run hasura cli commands you need to be in the graphql-engine/stagency folder
(next to the config.yaml file).
> cd ./graphql-engine/stagency
> hasura console
Database migrations and Hasura metadata are automatically applied when starting the
Docker environment. This can take a little time so if you get a connection error running
hasura console right after starting the Docker environment, wait 30 seconds and try
again. You can also keep an eye on the Docker logs with docker compose logs -f to watch
the migration status.
You can also see what migrations have been applied with
> hasura migrate status
VERSION NAME SOURCE STATUS DATABASE STATUS
1629994276879 Adding data ingestion tables... Present Present
1632438246782 add_inbound_email_attachment... Present Present
Hasura is used to manage database migrations which means all schema changes need to be performed through the Hasura CLI or Console.
The simplest way to edit the schema is through the Hasura Console.
- run
hasura consolefrom thegraphql-engine/stagencyfolder
- This opens a web browser with the Hasura Console UI
- Make any changes you want to the database or object relationships through the Console UI
- This will track changes in migration files for every change you make.
- You can find some documentation on this process here
- When your feature is ready for PR, squash your migrations into a single migration file for the current feature.
- This is described in the migrations documentation
- And the hasura migrate docs
- Commit everything in the
graphql-engine/stagencyfolder and push your changes.
It's also possible to create schema migration files directly through the Hasura CLI. This requires running the hasura migrate create command with the text of the migration you want to apply.
> hasura migrate create \
migration-name \
--up-sql "CREATE TABLE article(id serial NOT NULL, title text NOT NULL, content text NOT NULL);" \
--down-sql "DROP TABLE article;""
This will generate up and down migration files in the graphql-engine/stagency/migrations folder. You'll next need
to track the metadata for your schema changes by either running hasura console and making updates there or by
manually editing the metadata files as described in the
docs
If you really want to, you can also manually create and edit migration files as described in the hasura docs.
Sometimes you may find yourself in a situation where the Hasura metadata does not match the database schema. In these
situations, you'll receive an error from Hasura CLI or the web console that WARN Metadata is inconsistent. To resolve
the errors you can either fix the Hasura metadata or migrate the database to the correct version as follows.
To fix the Hasura metadata, use the
hasura metadata ic list to
list all of the relationships that are inconsistent. Note the relationships and then use the button in the Console to
remove all inconsistent metadata fields. Then manually fix any relationships from the previous inconsistencies list
using the Console UI.
You can also perform all of these tasks through the CLI if you prefer.
If the Hasura metadata is correct but the database schema is old, you can use hasura migrate apply to apply all Hasura
migrations to bring the database in sync with the metadata. You may also need to reapply the Hasura metadata with
hasura metdata apply.
If you need to reset Hasura and the database to a fresh state, you can use the following commands.
> hasura metadata clear
> hasura migrate delete --all --server --database-name defaultIf you want to verify the current state, use hasura migrate status:
> hasura migrate status
Database: default
VERSION NAME SOURCE STATUS DATABASE STATUS
1644204563684 init Present Not Present
1650058433523 alter_table_app_deal_add_deal_status_type Present Not PresentYou can now re-apply all Hasura migrations and metadata:
> hasura migrate apply
> hasura metadata applyDocker needs to be told explicitly to close all running app containers. Simply exiting out of the terminal will not properly stop them, and issues will arise if you try to run the application again. Use this command to properly close the application.
> docker-compose down -v
The
-v(or--volumes) flag will shut down the volumes used to store data. This will ensure the database starts up in a completely fresh state.
A lot of the frontend development happens in our component library provided by Storybook. You can startup storybook with
> cd react-frontend
> yarn storybook
More information is provided in the react-frontend README