File tree Expand file tree Collapse file tree 4 files changed +189
-18
lines changed Expand file tree Collapse file tree 4 files changed +189
-18
lines changed Original file line number Diff line number Diff line change 16
16
"@remix-run/node" : " ^1.5.1" ,
17
17
"@remix-run/react" : " ^1.5.1" ,
18
18
"@remix-run/serve" : " ^1.5.1" ,
19
+ "bcrypt" : " ^5.0.1" ,
19
20
"prisma" : " ^3.14.0" ,
20
21
"react" : " ^17.0.2" ,
21
22
"react-dom" : " ^17.0.2"
22
23
},
23
24
"devDependencies" : {
24
25
"@remix-run/dev" : " ^1.5.1" ,
25
26
"@remix-run/eslint-config" : " ^1.5.1" ,
27
+ "@types/bcrypt" : " ^5.0.0" ,
26
28
"@types/node" : " ^17.0.35" ,
27
29
"@types/react" : " ^17.0.45" ,
28
30
"@types/react-dom" : " ^17.0.17" ,
Original file line number Diff line number Diff line change @@ -10,10 +10,21 @@ datasource db {
10
10
url = env (" DATABASE_URL " )
11
11
}
12
12
13
+ model User {
14
+ id String @id @default (uuid () )
15
+ createdAt DateTime @default (now () )
16
+ updatedAt DateTime @updatedAt
17
+ username String @unique
18
+ passwordHash String
19
+ jokes Joke []
20
+ }
21
+
13
22
model Joke {
14
- id String @id @default (uuid () )
15
- createdAt DateTime @default (now () )
16
- updatedAt DateTime @updatedAt
17
- name String
18
- content String
23
+ id String @id @default (uuid () )
24
+ jokesterId String
25
+ jokester User @relation (fields : [jokesterId ] , references : [id ] , onDelete : Cascade )
26
+ createdAt DateTime @default (now () )
27
+ updatedAt DateTime @updatedAt
28
+ name String
29
+ content String
19
30
}
Original file line number Diff line number Diff line change 1
1
import { PrismaClient } from "@prisma/client" ;
2
+ import bcrypt from "bcrypt" ;
2
3
3
4
const db = new PrismaClient ( ) ;
4
5
@@ -42,7 +43,20 @@ const getJokes = () => [
42
43
] ;
43
44
44
45
const seed = async ( ) => {
45
- await Promise . all ( getJokes ( ) . map ( ( joke ) => db . joke . create ( { data : joke } ) ) ) ;
46
+ // Hash a password
47
+ const password = await bcrypt . hash ( "ankurpaul" , 10 ) ;
48
+ const kody = await db . user . create ( {
49
+ data : {
50
+ username : "ankurpaul" ,
51
+ passwordHash : password ,
52
+ } ,
53
+ } ) ;
54
+
55
+ await Promise . all (
56
+ getJokes ( ) . map ( ( joke ) =>
57
+ db . joke . create ( { data : { jokesterId : kody . id , ...joke } } )
58
+ )
59
+ ) ;
46
60
} ;
47
61
48
62
seed ( ) ;
You can’t perform that action at this time.
0 commit comments