Skip to content

Commit 75bf2c0

Browse files
authored
Merge pull request #2 from UTDallasEPICS/prisma-defaults
Quality of life changes for Prisma. 1. Make prisma generate IDs if none are provided 2. Make the reset command runn all prisma things at once 3. Modify seeding to better fit email OTPs
2 parents e131752 + 97914a8 commit 75bf2c0

4 files changed

Lines changed: 14 additions & 53 deletions

File tree

README.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,8 @@ Open `.env` and configure the following:
5959

6060
### 4. Database Setup
6161

62-
Initialize your SQLite database and run migrations.
63-
64-
```bash
65-
pnpm dlx prisma migrate dev --name init
66-
```
67-
68-
Generate the Prisma client
69-
70-
```bash
71-
pnpm dlx prisma generate
72-
```
73-
74-
To reset the database and run the seed script:
62+
Initialize your SQLite database and run migrations. You will need to run this command anytime you need to change or create a database.
63+
If there are any migrations that need to be run, the command will ask for a name for the migration. You can simply hit enter, or name your migration.
7564

7665
```bash
7766
pnpm prisma:reset
@@ -90,7 +79,7 @@ Your application will be available at `http://localhost:3000`. This command also
9079
Login requires an email address that already exists in the database.
9180

9281
- **Option A: Use the seeded user**
93-
Go to `/auth` and log in with `alice@a.com`.
82+
Go to `/auth` and log in with `email@example.com`.
9483
- **Option B: Use your own email**
9584
Update `prisma/seed.ts` with your email, then run `pnpm prisma:reset` to re-seed.
9685

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"generate": "nuxt generate",
99
"preview": "nuxt preview",
1010
"postinstall": "nuxt prepare",
11-
"prisma:reset": "prisma migrate reset -f && prisma db seed"
11+
"prisma:reset": "prisma migrate reset -f && prisma migrate dev && prisma generate && prisma db seed"
1212
},
1313
"dependencies": {
1414
"@nuxt/image": "2.0.0",

prisma/schema.prisma

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ datasource db {
88
}
99

1010
model User {
11-
id String @id
11+
id String @id @default(uuid())
1212
name String
1313
email String
1414
emailVerified Boolean @default(false)
@@ -23,7 +23,7 @@ model User {
2323
}
2424

2525
model Session {
26-
id String @id
26+
id String @id @default(uuid())
2727
expiresAt DateTime
2828
token String
2929
createdAt DateTime @default(now())
@@ -39,7 +39,7 @@ model Session {
3939
}
4040

4141
model Account {
42-
id String @id
42+
id String @id @default(uuid())
4343
accountId String
4444
providerId String
4545
userId String
@@ -59,7 +59,7 @@ model Account {
5959
}
6060

6161
model Verification {
62-
id String @id
62+
id String @id @default(uuid())
6363
identifier String
6464
value String
6565
expiresAt DateTime

prisma/seed.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,20 @@
1-
import { Param } from '@prisma/client/runtime/client'
21
import { prisma } from '../server/utils/prisma'
32

43
async function main() {
54
console.log('Start seeding...')
65

7-
// 1. Create a User with a Password (Local Auth)
6+
// Create a User
87
const user1 = await prisma.user.create({
98
data: {
10-
id: 'user_01',
11-
name: 'Alice Developer',
12-
email: 'alice@a.com',
13-
emailVerified: true,
14-
accounts: {
15-
create: {
16-
id: 'acc_01',
17-
accountId: 'alice_local_id',
18-
providerId: 'credential', // Common for email/password
19-
password: 'hashed_password_here', // In a real app, hash this!
20-
},
21-
},
22-
},
9+
name: "Sample Name", // modify this fit your needs
10+
email: "email@example.com"
11+
}
2312
})
2413

25-
// 2. Create a User with an OAuth Account (e.g., Google)
26-
const user2 = await prisma.user.create({
27-
data: {
28-
id: 'user_02',
29-
name: 'Bob Tester',
30-
email: 'bob@b.com',
31-
emailVerified: true,
32-
accounts: {
33-
create: {
34-
id: 'acc_02',
35-
accountId: 'bob_google_id',
36-
providerId: 'google',
37-
accessToken: 'mock_access_token',
38-
},
39-
},
40-
},
41-
})
42-
43-
console.log({ user1, user2 })
14+
console.log({ user1 })
4415
console.log('Seeding finished.')
4516
}
17+
// You can seed other models in your db as well depending on project needs
4618

4719
main()
4820
.then(async () => {

0 commit comments

Comments
 (0)