Skip to content

Commit 2f10cad

Browse files
committed
prepare server and db
used project from https://www.howtographql.com/graphql-js/0-introduction
1 parent 8dc8ffc commit 2f10cad

20 files changed

+5675
-0
lines changed

server/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.env*
2+
dist
3+
4+
node_modules
5+
.idea
6+
.vscode
7+
*.log

server/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# hackernews-graphql-js
2+
3+
This repository contains the final project for the [**GraphQL.js tutorial**](https://www.howtographql.com/graphql-js/0-introduction/) on [How to GraphQL](https://www.howtographql.com/). Note that it also serves as foundation for all frontend tutorials on the site.

server/package-lock.json

+2,503
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "hackernews-node",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"scripts": {
6+
"start": "node src/index.js",
7+
"dev": "nodemon src/index.js"
8+
},
9+
"dependencies": {
10+
"@prisma/client": "^2.16.1",
11+
"apollo-server": "^2.19.0",
12+
"bcryptjs": "2.4.3",
13+
"jsonwebtoken": "8.5.1"
14+
},
15+
"devDependencies": {
16+
"@prisma/cli": "^2.12.1",
17+
"nodemon": "^2.0.6"
18+
}
19+
}

server/prisma/dev.db

48 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Migration `20201125185150-init`
2+
3+
This migration has been generated by Ryan Chenkie at 11/25/2020, 1:51:50 PM.
4+
You can check out the [state of the schema](./schema.prisma) after the migration.
5+
6+
## Database Steps
7+
8+
```sql
9+
CREATE TABLE "Link" (
10+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
11+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
12+
"description" TEXT NOT NULL,
13+
"url" TEXT NOT NULL,
14+
"postedById" INTEGER NOT NULL,
15+
16+
FOREIGN KEY ("postedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE
17+
)
18+
19+
CREATE TABLE "User" (
20+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
21+
"name" TEXT NOT NULL,
22+
"email" TEXT NOT NULL,
23+
"password" TEXT NOT NULL
24+
)
25+
26+
CREATE TABLE "Vote" (
27+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
28+
"linkId" INTEGER NOT NULL,
29+
"userId" INTEGER NOT NULL,
30+
31+
FOREIGN KEY ("linkId") REFERENCES "Link"("id") ON DELETE CASCADE ON UPDATE CASCADE,
32+
FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE
33+
)
34+
35+
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email")
36+
37+
CREATE UNIQUE INDEX "Vote.linkId_userId_unique" ON "Vote"("linkId", "userId")
38+
```
39+
40+
## Changes
41+
42+
```diff
43+
diff --git schema.prisma schema.prisma
44+
migration ..20201125185150-init
45+
--- datamodel.dml
46+
+++ datamodel.dml
47+
@@ -1,0 +1,37 @@
48+
+datasource db {
49+
+ provider = "sqlite"
50+
+ url = "***"
51+
+}
52+
+
53+
+generator client {
54+
+ provider = "prisma-client-js"
55+
+}
56+
+
57+
+model Link {
58+
+ id Int @id @default(autoincrement())
59+
+ createdAt DateTime @default(now())
60+
+ description String
61+
+ url String
62+
+ postedBy User @relation(fields: [postedById], references: [id])
63+
+ postedById Int
64+
+ votes Vote[]
65+
+}
66+
+
67+
+model User {
68+
+ id Int @id @default(autoincrement())
69+
+ name String
70+
+ email String @unique
71+
+ password String
72+
+ links Link[]
73+
+ votes Vote[]
74+
+}
75+
+
76+
+model Vote {
77+
+ id Int @id @default(autoincrement())
78+
+ link Link @relation(fields: [linkId], references: [id])
79+
+ linkId Int
80+
+ user User @relation(fields: [userId], references: [id])
81+
+ userId Int
82+
+
83+
+ @@unique([linkId, userId])
84+
+}
85+
```
86+
87+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
datasource db {
2+
provider = "sqlite"
3+
url = "***"
4+
}
5+
6+
generator client {
7+
provider = "prisma-client-js"
8+
}
9+
10+
model Link {
11+
id Int @id @default(autoincrement())
12+
createdAt DateTime @default(now())
13+
description String
14+
url String
15+
postedBy User @relation(fields: [postedById], references: [id])
16+
postedById Int
17+
votes Vote[]
18+
}
19+
20+
model User {
21+
id Int @id @default(autoincrement())
22+
name String
23+
email String @unique
24+
password String
25+
links Link[]
26+
votes Vote[]
27+
}
28+
29+
model Vote {
30+
id Int @id @default(autoincrement())
31+
link Link @relation(fields: [linkId], references: [id])
32+
linkId Int
33+
user User @relation(fields: [userId], references: [id])
34+
userId Int
35+
36+
@@unique([linkId, userId])
37+
}

0 commit comments

Comments
 (0)