Fixes and adjustments to demo

This commit is contained in:
Toni Koskinen
2026-03-27 10:37:42 +02:00
parent 51a4b84476
commit 4de890ba77
44 changed files with 1076 additions and 104 deletions

View File

@@ -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")
);

View File

@@ -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"

View File

@@ -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[]
}

View File

@@ -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
View 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);
});