Skip to content

Commit 7c0350f

Browse files
committed
Update schema and functions to adhere to conventions
1 parent 9e18d7d commit 7c0350f

File tree

4 files changed

+36
-46
lines changed

4 files changed

+36
-46
lines changed

functions/posts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const prisma = new PrismaClient()
55
exports.handler = async (event, context, callback) => {
66
try {
77
const posts = await prisma.post.findMany({
8-
include: { author_id: true }
8+
include: { author: true }
99
})
1010
return {
1111
statusCode: 200,

functions/seed.js

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,64 +29,50 @@ const seedUser = {
2929
3030
name: 'Jane',
3131
profile: {
32+
create: {
33+
bio: 'Health Enthusiast',
34+
},
35+
},
36+
posts: {
3237
create: [
3338
{
34-
bio: 'Technical Writer'
39+
title: 'Comparing Database Types: How Database Types Evolved to Meet Different Needs',
40+
content: 'https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/',
3541
},
3642
{
37-
bio: 'Health Enthusiast'
43+
title: 'Analysing Sleep Patterns: The Quantified Self',
44+
content: 'https://quantifiedself.com/get-started/',
3845
},
3946
{
40-
bio: 'Self Quantifier'
41-
}
42-
]
43-
},
44-
post: {
45-
create: [
46-
{
47-
title:
48-
'Comparing Database Types: How Database Types Evolved to Meet Different Needs',
49-
content:
50-
'https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/'
47+
title: 'Prisma 2 Docs',
48+
content: 'https://www.prisma.io/docs/',
5149
},
52-
{
53-
title: 'Analysing Sleep Patterns: The Quantified Self',
54-
content: 'https://quantifiedself.com/get-started/'
55-
}
56-
]
57-
}
50+
],
51+
},
5852
}
5953

6054
const seedUser2 = {
6155
6256
name: 'Toru Takemitsu',
6357
profile: {
64-
create: [
65-
{
66-
bio: 'Composer'
67-
},
68-
{
69-
bio: 'Musician'
70-
},
71-
{
72-
bio: 'Writer'
73-
}
74-
]
58+
create: {
59+
bio: 'Musician',
60+
},
7561
},
76-
post: {
62+
posts: {
7763
create: [
7864
{
7965
title: 'Requiem for String Orchestra',
80-
content: ''
66+
content: '',
8167
},
8268
{
8369
title: 'Music of Tree',
84-
content: ''
70+
content: '',
8571
},
8672
{
8773
title: 'Waves for clarinet, horn, two trombones and bass drum ',
88-
content: ''
89-
}
90-
]
91-
}
74+
content: '',
75+
},
76+
],
77+
},
9278
}

netlify.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[build]
2+
command = "npm run build"
3+
24
functions = "functions/"
35

46
publish = "public/"

schema.sql

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
CREATE TABLE "public"."User" (
2-
user_id SERIAL PRIMARY KEY NOT NULL,
2+
id SERIAL PRIMARY KEY NOT NULL,
33
name VARCHAR(255),
44
email VARCHAR(255) UNIQUE NOT NULL
55
);
66

77
CREATE TABLE "public"."Post" (
8-
post_id SERIAL PRIMARY KEY NOT NULL,
8+
id SERIAL PRIMARY KEY NOT NULL,
99
title VARCHAR(255) NOT NULL,
10+
"createdAt" TIMESTAMP NOT NULL DEFAULT now(),
1011
content TEXT,
11-
author_id INTEGER,
12-
FOREIGN KEY (author_id) REFERENCES "public"."User"(user_id)
12+
published BOOLEAN NOT NULL DEFAULT false,
13+
"authorId" INTEGER NOT NULL,
14+
FOREIGN KEY ("authorId") REFERENCES "public"."User"(id)
1315
);
1416

1517
CREATE TABLE "public"."Profile" (
16-
profile_id SERIAL PRIMARY KEY NOT NULL,
18+
id SERIAL PRIMARY KEY NOT NULL,
1719
bio TEXT,
18-
user_id INTEGER NOT NULL,
19-
FOREIGN KEY (user_id) REFERENCES "public"."User"(user_id)
20-
);
20+
"userId" INTEGER UNIQUE NOT NULL,
21+
FOREIGN KEY ("userId") REFERENCES "public"."User"(id)
22+
);

0 commit comments

Comments
 (0)