prisma db seeded

This commit is contained in:
Jacob Delgado 2023-10-29 19:29:43 -07:00
parent b886ea46b4
commit 890f0c91a4
8 changed files with 59 additions and 28 deletions

Binary file not shown.

View File

@ -1,19 +1,24 @@
{
"private": true,
"scripts": {
"build": "next build",
"build": "prisma generate && next build",
"dev": "next dev",
"start": "next start"
"start": "next start",
"introspect": "drizzle-kit introspect: pg --config=drizzle.config.ts",
"generate": "drizzle-kit generate:pg --config=drizzle.config.ts"
},
"prisma":{
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"dependencies": {
"@heroicons/react": "^2.0.18",
"@prisma/client": "5.5.2",
"@tailwindcss/forms": "^0.5.6",
"@types/node": "^20.8.9",
"@vercel/postgres": "^0.5.0",
"autoprefixer": "10.4.15",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"drizzle-orm": "^0.28.6",
"lucide-react": "^0.290.0",
"next": "^14.0.0",
"postcss": "8.4.31",
@ -26,15 +31,12 @@
"tailwindcss": "3.3.3",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.2.2",
"zod": "^3.22.2",
"dotenv":"16.3.1"
"zod": "^3.22.2"
},
"devDependencies": {
"@types/bcrypt": "^5.0.1",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.14",
"dotenv": "^16.3.1",
"drizzle-kit": "^0.19.13",
"prettier": "^3.0.3",
"ts-node": "^10.9.1"
},

View File

@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"password" TEXT NOT NULL,
"name" TEXT,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

View File

@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[email]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

View File

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"

View File

@ -9,3 +9,10 @@ datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
password String
name String?
}

View File

@ -0,0 +1,23 @@
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
const user = await prisma.user.upsert({
where: { email: 'test@test.com' },
update: {},
create: {
email: 'test@test.com',
name: 'Test User',
password: `testing1234`
}
})
console.log({ user })
}
main()
.then(() => prisma.$disconnect())
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})

View File

@ -1,21 +0,0 @@
import { integer, serial, text, pgTable } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
});
export const usersRelations = relations(users, ({ many }) => ({
posts: many(posts),
}));
export const posts = pgTable('posts', {
id: serial('id').primaryKey(),
content: text('content').notNull(),
authorId: integer('author_id').notNull(),
});
export const postsRelations = relations(posts, ({ one }) => ({
author: one(users, { fields: [posts.authorId], references: [users.id] }),
}));