-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.zmodel
47 lines (40 loc) · 1.04 KB
/
schema.zmodel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* A sample data source using local sqlite db.
* See how to use a different db: https://zenstack.dev/#/zmodel-data-source.
*/
datasource db {
provider = 'sqlite'
url = 'file:./dev.db'
}
generator client {
provider = "prisma-client-js"
}
/*
* User model
*/
model User {
id String @id @default(cuid())
email String @unique @email
password String @password @omit @length(8, 16)
posts Post[]
// everybody can signup
@@allow('create,read', true)
// full access by self
@@allow('all', auth() == this)
}
/*
* Post model
*/
model Post {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @length(1, 256)
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId String? @default(auth().id)
// allow read for all signin users
@@allow('read', auth() != null && published)
// full access by author
@@allow('all', author == auth())
}