You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,21 @@ cp .example.env .env
100
100
## Dev Services
101
101
102
102
## Database
103
+
104
+
### Database Views
105
+
106
+
The access policies and users documents are implemented as database views. To keep track of views and changes, make sure to use `yarn db:migrate-views` when changing views:
107
+
108
+
1. Edit or create a new view file in `prisma/view-migrations/views/`.
109
+
2. Make sure the dependencies are correct in [migrate.config.yml](prisma/view-migrations/migrate.config.yml).
110
+
3. Run `yarn db:migrate-views` to create a new migration for the changed views (this won't run `prisma migrate:dev`, it only creates the migration files).
111
+
4. Eventually change the [schema.prisma](prisma/schema.prisma) file to reflect changes in the views (e.g. new fields).
112
+
5. Run `yarn run prisma migrate:dev` to create a new migration for the schema changes.
113
+
114
+
> [!WARNING]
115
+
> Never edit views directly in a prisma migration file (under `prisma/migrations/`), as these files are auto-generated and will be overwritten the next time `yarn db:migrate-views` is run.
116
+
117
+
103
118
### Docker Compose
104
119
105
120
Run `scripts/purge_dev_services.sh` or the `purge_dev_services` run config to remove all containers **and volumes** associated with the dev services.
) FILTER (WHEREview__document_user_permissions.root_user_permission_idIS NOT NULL),
24
+
'[]'::jsonb
25
+
) AS"userPermissions",
26
+
COALESCE(
27
+
JSONB_AGG(
28
+
JSONB_BUILD_OBJECT(
29
+
'id', d.id,
30
+
'authorId', d.author_id,
31
+
'type', d.type,
32
+
'data', CASE WHEN (view__document_user_permissions.access='None_DocumentRoot'ORview__document_user_permissions.access='None_StudentGroup'ORview__document_user_permissions.access='None_User') THEN NULL ELSE d.data END,
33
+
'parentId', d.parent_id,
34
+
'documentRootId', d.document_root_id,
35
+
'createdAt', d.created_at,
36
+
'updatedAt', d.updated_at
37
+
)
38
+
) FILTER (WHEREd.idIS NOT NULL),
39
+
'[]'::jsonb
40
+
) AS documents
41
+
FROM
42
+
document_roots
43
+
LEFT JOIN view__document_user_permissions ONdocument_roots.id=view__document_user_permissions.document_root_id
44
+
LEFT JOIN documents d ONdocument_roots.id=d.document_root_idANDview__document_user_permissions.document_id=d.id
45
+
WHEREview__document_user_permissions.user_idIS NOT NULL
46
+
GROUP BYdocument_roots.id, view__document_user_permissions.user_id
0 commit comments