Skip to content

Commit dc39037

Browse files
committed
update to v2
1 parent ac5c314 commit dc39037

File tree

5 files changed

+95
-80
lines changed

5 files changed

+95
-80
lines changed

package-lock.json

+63-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"lint": "prettier --plugin-search-dir . --check . && eslint .",
1313
"format": "prettier --plugin-search-dir . --write .",
1414
"package-clean": "npm rm zenstack @zenstackhq/runtime",
15-
"up": "npm run package-clean && npm install -D --save-exact zenstack@next && npm install --save-exact @zenstackhq/runtime@next"
15+
"up": "npm run package-clean && npm install -D --save-exact zenstack@latest && npm install --save-exact @zenstackhq/runtime@latest"
1616
},
1717
"devDependencies": {
1818
"@sveltejs/adapter-auto": "^2.0.0",
@@ -35,12 +35,12 @@
3535
"tslib": "^2.4.1",
3636
"typescript": "^5.0.0",
3737
"vite": "^4.3.0",
38-
"zenstack": "2.0.0-beta.10"
38+
"zenstack": "^2.0.0"
3939
},
4040
"type": "module",
4141
"dependencies": {
4242
"@prisma/client": "^5.12.1",
43-
"@zenstackhq/runtime": "2.0.0-beta.10",
43+
"@zenstackhq/runtime": "^2.0.0",
4444
"bcryptjs": "^2.4.3",
4545
"jsonwebtoken": "^9.0.0"
4646
}

prisma/schema.prisma

+20-20
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@
44
//////////////////////////////////////////////////////////////////////////////////////////////
55

66
datasource db {
7-
provider = "sqlite"
8-
url = "file:./dev.db"
7+
provider = "sqlite"
8+
url = "file:./dev.db"
99
}
1010

1111
generator client {
12-
provider = "prisma-client-js"
12+
provider = "prisma-client-js"
1313
}
1414

1515
/// @@allow('create,read', true)
1616
/// @@allow('all', auth() == this)
1717
model User {
18-
id String @id() @default(cuid())
19-
/// @email
20-
email String @unique()
21-
/// @password
22-
/// @omit
23-
/// @length(8, 16)
24-
password String
25-
posts Post[]
18+
id String @id() @default(cuid())
19+
/// @email
20+
email String @unique()
21+
/// @password
22+
/// @omit
23+
/// @length(8, 16)
24+
password String
25+
posts Post[]
2626
}
2727

2828
/// @@allow('read', auth() != null && published)
2929
/// @@allow('all', author == auth())
3030
model Post {
31-
id String @id() @default(cuid())
32-
createdAt DateTime @default(now())
33-
updatedAt DateTime @updatedAt()
34-
/// @length(1, 256)
35-
title String
36-
published Boolean @default(false)
37-
author User? @relation(fields: [authorId], references: [id])
38-
authorId String?
39-
}
31+
id String @id() @default(cuid())
32+
createdAt DateTime @default(now())
33+
updatedAt DateTime @updatedAt()
34+
/// @length(1, 256)
35+
title String
36+
published Boolean @default(false)
37+
author User? @relation(fields: [authorId], references: [id])
38+
authorId String?
39+
}

schema.zmodel

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// This is a sample model to get you started.
2-
// Learn how to model you app: https://zenstack.dev/#/modeling-your-app.
3-
41
/*
52
* A sample data source using local sqlite db.
63
* See how to use a different db: https://zenstack.dev/#/zmodel-data-source.
@@ -18,10 +15,10 @@ generator client {
1815
* User model
1916
*/
2017
model User {
21-
id String @id @default(cuid())
22-
email String @unique @email
18+
id String @id @default(cuid())
19+
email String @unique @email
2320
password String @password @omit @length(8, 16)
24-
posts Post[]
21+
posts Post[]
2522

2623
// everybody can signup
2724
@@allow('create,read', true)
@@ -34,13 +31,13 @@ model User {
3431
* Post model
3532
*/
3633
model Post {
37-
id String @id @default(cuid())
34+
id String @id @default(cuid())
3835
createdAt DateTime @default(now())
3936
updatedAt DateTime @updatedAt
40-
title String @length(1, 256)
41-
published Boolean @default(false)
42-
author User? @relation(fields: [authorId], references: [id])
43-
authorId String?
37+
title String @length(1, 256)
38+
published Boolean @default(false)
39+
author User? @relation(fields: [authorId], references: [id])
40+
authorId String? @default(auth().id)
4441

4542
// allow read for all signin users
4643
@@allow('read', auth() != null && published)

src/routes/+page.server.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export const actions: Actions = {
1818
return fail(400, { missing: true });
1919
}
2020

21-
await locals.db.post.create({
22-
data: { title, author: { connect: { id: locals.user?.id } } }
23-
});
21+
await locals.db.post.create({ data: { title } });
2422

2523
return { success: true };
2624
},

0 commit comments

Comments
 (0)