Skip to content

Commit fb9280d

Browse files
authored
Wire up db's for migrations (#17)
1 parent 031b294 commit fb9280d

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

README.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ In Maori, "wai pai" translates to _good water_.
1515

1616
Head over to [Hasura's website](https://hasura.io/) and follow their 30 second Heroku setup
1717

18-
```javascript
18+
```bash
1919
$ git clone [email protected]:evanheisler/waipai.git && cd waipai
2020
$ yarn
2121
$ cp .env.example .env // update API variable to your heroku instance
22+
```
23+
24+
```bash
2225
$ yarn start
2326
```
2427

@@ -28,16 +31,24 @@ These steps will give you a local setup, as opposed to developing against a Hero
2831

2932
Follow the Quickstart steps, but for your `.env` API variable, use `http://localhost:8080/v1/graphql`. Confirm that `docker` and `psql` are running, then:
3033

31-
```javascript
34+
```bash
3235
$ cp docker-run.sh.example docker-run.sh // update database_url with your name, password and database instance
3336
$ ./docker-run.sh
3437
$ docker ps // confirm Hasura container is running
38+
$ cd server
39+
$ hasura migrate apply --endpoint http://localhost:8080
3540
```
3641

37-
You should now have a server at visit http://localhost:8080 and a web client at visit http://localhost:3000.
42+
```bash
43+
cd server && hasura console
44+
```
45+
46+
You should now have a server at http://localhost:9695/api-explorer and a web client at http://localhost:3000.
3847

3948
## Running Tests
4049

4150
## Deployment
4251

43-
Using webhooks, new tags will deliver bundles to Netlify (frontend) and Heroku (backend).
52+
Frontend: Previews will be generated with pull requests via webhooks. Tagged releases will create production builds.
53+
54+
Backend: Run migrations with `hasura migrate apply --endpoint http://your-prod-instance.herokuapp.com` (requires heroku cli login)

docker-run.sh.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/bash
22
docker run -d -p 8080:8080 \
33
-e HASURA_GRAPHQL_DATABASE_URL=postgres://username:[email protected]:5432/dbname \
4-
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
4+
-e HASURA_GRAPHQL_ENABLE_CONSOLE=false \
55
hasura/graphql-engine:v1.1.1

server/config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
endpoint: http://localhost:8080
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE public.posts (
2+
post_id uuid DEFAULT public.gen_random_uuid() NOT NULL,
3+
content text NOT NULL,
4+
is_public boolean DEFAULT false NOT NULL,
5+
author_id uuid NOT NULL,
6+
created_at timestamp with time zone DEFAULT now() NOT NULL,
7+
updated_at timestamp with time zone
8+
);
9+
CREATE TABLE public.users (
10+
id uuid DEFAULT public.gen_random_uuid() NOT NULL,
11+
full_name text NOT NULL,
12+
user_name text NOT NULL,
13+
email text NOT NULL,
14+
created_at timestamp with time zone DEFAULT now() NOT NULL
15+
);
16+
ALTER TABLE ONLY public.posts
17+
ADD CONSTRAINT posts_pkey PRIMARY KEY (post_id);
18+
ALTER TABLE ONLY public.users
19+
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
20+
ALTER TABLE ONLY public.posts
21+
ADD CONSTRAINT posts_author_id_fkey FOREIGN KEY (author_id) REFERENCES public.users(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- args:
2+
tables:
3+
- object_relationships:
4+
- name: user
5+
using:
6+
foreign_key_constraint_on: author_id
7+
table:
8+
name: posts
9+
schema: public
10+
- table:
11+
name: users
12+
schema: public
13+
version: 2
14+
type: replace_metadata

0 commit comments

Comments
 (0)