diff --git a/README.md b/README.md index d4f1468..6117985 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/package.json b/package.json index c731536..2403d0e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dfcf9fe..48a3da2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,7 +8,7 @@ datasource db { } model User { - id String @id + id String @id @default(uuid()) name String email String emailVerified Boolean @default(false) @@ -23,7 +23,7 @@ model User { } model Session { - id String @id + id String @id @default(uuid()) expiresAt DateTime token String createdAt DateTime @default(now()) @@ -39,7 +39,7 @@ model Session { } model Account { - id String @id + id String @id @default(uuid()) accountId String providerId String userId String @@ -59,7 +59,7 @@ model Account { } model Verification { - id String @id + id String @id @default(uuid()) identifier String value String expiresAt DateTime diff --git a/prisma/seed.ts b/prisma/seed.ts index 68ea760..578dd88 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -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 () => {