Skip to content

Commit b4849f7

Browse files
authored
Fix documentation relating to migrations (#268)
1 parent db6a5d6 commit b4849f7

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

@app/db/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ may prefer to switch this out for your preferred migration framework such as
1919
Should you decide to stick with Graphile Migrate, we strongly encourage you to
2020
[read the Graphile Migrate README](https://github.com/graphile/migrate/blob/main/README.md)
2121
before attempting to write your own migrations. Graphile Migrate works in quite
22-
a different way to many other migration frameworks, and relys on your discipline
23-
and SQL knowledge to work well.
22+
a different way to many other migration frameworks, and relies on your
23+
discipline and SQL knowledge to work well.
2424

2525
If you're not very comfortable with SQL then we recommend you use an alternative
2626
migration framework (for now at least, Graphile Migrate is still young...)
2727

28+
[Read more about the migrations in `migrations/README.md`.](./migrations/README.md)
29+
2830
## Database Roles
2931

3032
Graphile Starter uses three roles:
@@ -45,7 +47,7 @@ Graphile Starter uses three roles:
4547
queries runs as, it's what the vast majority of your `GRANT`s will reference
4648
and the row level security policies will apply to. It represents both logged
4749
in AND logged out users to your GraphQL API - it's assumed that your Row Level
48-
Security policies will deferentiate between these states (and any other
50+
Security policies will differentiate between these states (and any other
4951
"application roles" the user may have) to determine what they are permitted to
5052
do.
5153

@@ -59,3 +61,10 @@ dev, production), not with your own user role nor the default superuser role
5961
(often named `postgres`). This ensures that the system behaves as expected when
6062
graduating from your local dev environment to hosted database systems in
6163
production.
64+
65+
## \_\_tests\_\_/
66+
67+
Our database tests are written in Jest, enabling you to call database functions
68+
or run SQL and perform your regular assertions against them. We've added a
69+
number of helpers to make this easier; read more in the
70+
[\_\_tests\_\_ README](./__tests__/README.md).

@app/db/migrations/README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Migrations
22

33
This folder contains the database migrations. We're using the `graphile-migrate`
4-
project to produce these; we highly recommend you read the README before
5-
implementing your own migrations:
4+
project to produce these; we highly recommend you
5+
[read the Graphile Migrate README](https://github.com/graphile/migrate/blob/main/README.md)
6+
before implementing your own migrations.
67

7-
https://github.com/graphile/migrate/blob/main/README.md
8-
9-
The main file you'll be working with is `current.sql`.
8+
The main files you'll be working with are those in the `current/` folder.
109

1110
## afterReset.sql
1211

@@ -15,12 +14,16 @@ currently grants permissions to the relevant roles and creates the required
1514
extensions. It's expected that this is ran with database superuser privileges as
1615
normal users often don't have sufficient permissions to install extensions.
1716

18-
## current.sql
17+
## current/\*.sql
1918

2019
This is where your new database changes go. They need to be idempotent (for
21-
details read the README above). The `yarn start` command will automatically
22-
watch this file and re-run it whenever it changes, updating your database in
23-
realtime.
20+
explanation
21+
[read the Graphile Migrate README](https://github.com/graphile/migrate/blob/main/README.md)).
22+
The `yarn start` command will automatically watch these files and re-run them
23+
whenever they change, updating your database in realtime. Each file needs a
24+
unique positive integer prefix, we've started you off with
25+
`current/1-current.sql` but you can add more if it helps you structure your
26+
migration more cleanly.
2427

2528
**IMPORTANT**: because we use `ignoreRBAC: false` in PostGraphile's
2629
configuration, new tables _will not show up_ until you `GRANT` permissions on
@@ -42,7 +45,7 @@ grant
4245
on app_public.my_new_table to :DATABASE_VISITOR;
4346
```
4447

45-
## committed
48+
## committed/\*.sql
4649

4750
When you're happy with the changes you have made, you can commit your migration
4851
with
@@ -51,9 +54,10 @@ with
5154
yarn db commit
5255
```
5356

54-
This will call `graphile-migrate commit` which involves moving `current.sql`
55-
into the `committed` folder, and hashing it to prevent later modifications
56-
(which should instead be done with additional migrations).
57+
This will call `graphile-migrate commit` which involves merging the
58+
`current/*.sql` files together and then putting the result into the `committed`
59+
folder with a hash to prevent later modifications (which should instead be done
60+
with additional migrations).
5761

5862
If you've not yet merged your changes (and no-one else has ran them) then you
5963
can run
@@ -64,9 +68,3 @@ yarn db uncommit
6468

6569
and it will perform the reverse of this process so that you may modify the
6670
migrations again.
67-
68-
## **tests**
69-
70-
Our database tests are written in Jest, enabling you to call database functions
71-
or run SQL and perform your regular assertions against them. We've added a
72-
number of helpers to make this easier.

0 commit comments

Comments
 (0)