Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,8 @@ Open `.env` and configure the following:

### 4. Database Setup

Initialize your SQLite database and run migrations.

```bash
pnpm dlx prisma migrate dev --name init
```

Generate the Prisma client

```bash
pnpm dlx prisma generate
```

To reset the database and run the seed script:
Initialize your SQLite database and run migrations. You will need to run this command anytime you need to change or create a database.
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.

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

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"prisma:reset": "prisma migrate reset -f && prisma db seed"
"prisma:reset": "prisma migrate reset -f && prisma migrate dev && prisma generate && prisma db seed"
},
"dependencies": {
"@nuxt/image": "2.0.0",
Expand Down
8 changes: 4 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ datasource db {
}

model User {
id String @id
id String @id @default(uuid())
name String
email String
emailVerified Boolean @default(false)
Expand All @@ -23,7 +23,7 @@ model User {
}

model Session {
id String @id
id String @id @default(uuid())
expiresAt DateTime
token String
createdAt DateTime @default(now())
Expand All @@ -39,7 +39,7 @@ model Session {
}

model Account {
id String @id
id String @id @default(uuid())
accountId String
providerId String
userId String
Expand All @@ -59,7 +59,7 @@ model Account {
}

model Verification {
id String @id
id String @id @default(uuid())
identifier String
value String
expiresAt DateTime
Expand Down
40 changes: 6 additions & 34 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,20 @@
import { Param } from '@prisma/client/runtime/client'
import { prisma } from '../server/utils/prisma'

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

// 1. Create a User with a Password (Local Auth)
// Create a User
const user1 = await prisma.user.create({
data: {
id: 'user_01',
name: 'Alice Developer',
email: 'alice@a.com',
emailVerified: true,
accounts: {
create: {
id: 'acc_01',
accountId: 'alice_local_id',
providerId: 'credential', // Common for email/password
password: 'hashed_password_here', // In a real app, hash this!
},
},
},
name: "Sample Name", // modify this fit your needs
email: "email@example.com"
}
})

// 2. Create a User with an OAuth Account (e.g., Google)
const user2 = await prisma.user.create({
data: {
id: 'user_02',
name: 'Bob Tester',
email: 'bob@b.com',
emailVerified: true,
accounts: {
create: {
id: 'acc_02',
accountId: 'bob_google_id',
providerId: 'google',
accessToken: 'mock_access_token',
},
},
},
})

console.log({ user1, user2 })
console.log({ user1 })
console.log('Seeding finished.')
}
// You can seed other models in your db as well depending on project needs

main()
.then(async () => {
Expand Down