Fixes and adjustments to demo
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "PostStatus" AS ENUM ('DRAFT', 'PUBLISHED', 'ARCHIVED');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "posts" (
|
||||
"id" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"content" TEXT,
|
||||
"status" "PostStatus" NOT NULL DEFAULT 'DRAFT',
|
||||
"authorName" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "posts_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
@@ -1,3 +0,0 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (e.g., Git)
|
||||
provider = "postgresql"
|
||||
@@ -19,13 +19,20 @@ enum PostStatus {
|
||||
|
||||
// Simple table for blog posts
|
||||
model Post {
|
||||
id String @id @default(cuid())
|
||||
id String @id @unique @default(cuid())
|
||||
title String
|
||||
content String?
|
||||
status PostStatus @default(DRAFT)
|
||||
authorName String
|
||||
published Boolean
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId String
|
||||
|
||||
@@map("posts")
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @unique @default(cuid())
|
||||
email String @unique
|
||||
name String
|
||||
posts Post[]
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
INSERT INTO "posts" ("id","title","content","status","authorName","createdAt","updatedAt")
|
||||
VALUES
|
||||
('post_1','Hello Prisma','First seeded post','DRAFT','Alice',NOW(),NOW()),
|
||||
('post_2','Published post','Seeded and published','PUBLISHED','Bob',NOW(),NOW())
|
||||
ON CONFLICT ("id") DO NOTHING;
|
||||
56
prisma/seedData.ts
Normal file
56
prisma/seedData.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import "dotenv/config";
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { PrismaClient } from "../libs/prisma-generated/src/client";
|
||||
|
||||
const connectionString = `${process.env.DATABASE_URL}`;
|
||||
const adapter = new PrismaPg({ connectionString });
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
async function main() {
|
||||
const alice = await prisma.user.upsert({
|
||||
where: { email: "alice@prisma.io" },
|
||||
update: {},
|
||||
create: {
|
||||
email: "alice@prisma.io",
|
||||
name: "Alice",
|
||||
posts: {
|
||||
create: {
|
||||
title: "Check out Prisma with Next.js",
|
||||
content: "https://www.prisma.io/nextjs",
|
||||
published: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const bob = await prisma.user.upsert({
|
||||
where: { email: "bob@prisma.io" },
|
||||
update: {},
|
||||
create: {
|
||||
email: "bob@prisma.io",
|
||||
name: "Bob",
|
||||
posts: {
|
||||
create: [
|
||||
{
|
||||
title: "Check out the code in gitea",
|
||||
content: "https://gitea.tonssikas.ovh",
|
||||
published: true,
|
||||
},
|
||||
{
|
||||
title: "A third example card",
|
||||
content: "https://google.com",
|
||||
published: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log({ alice, bob });
|
||||
}
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect();
|
||||
})
|
||||
.catch(async (e) => {
|
||||
console.error(e);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user