1
1
# Migrations
2
2
3
3
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.
6
7
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.
10
9
11
10
## afterReset.sql
12
11
@@ -15,12 +14,16 @@ currently grants permissions to the relevant roles and creates the required
15
14
extensions. It's expected that this is ran with database superuser privileges as
16
15
normal users often don't have sufficient permissions to install extensions.
17
16
18
- ## current.sql
17
+ ## current/ \* .sql
19
18
20
19
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.
24
27
25
28
** IMPORTANT** : because we use ` ignoreRBAC: false ` in PostGraphile's
26
29
configuration, new tables _ will not show up_ until you ` GRANT ` permissions on
42
45
on app_public .my_new_table to :DATABASE_VISITOR;
43
46
```
44
47
45
- ## committed
48
+ ## committed/ \* .sql
46
49
47
50
When you're happy with the changes you have made, you can commit your migration
48
51
with
51
54
yarn db commit
52
55
```
53
56
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).
57
61
58
62
If you've not yet merged your changes (and no-one else has ran them) then you
59
63
can run
@@ -64,9 +68,3 @@ yarn db uncommit
64
68
65
69
and it will perform the reverse of this process so that you may modify the
66
70
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