first commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
enum PostType {
|
||||
notebook
|
||||
sticky
|
||||
polaroid
|
||||
code
|
||||
audio
|
||||
|
||||
@@map("post_type")
|
||||
}
|
||||
|
||||
enum MoodType {
|
||||
focus
|
||||
night
|
||||
spark
|
||||
calm
|
||||
visual
|
||||
|
||||
@@map("mood_type")
|
||||
}
|
||||
|
||||
model Post {
|
||||
id String @id @default(cuid())
|
||||
type PostType
|
||||
date String
|
||||
timestamp String
|
||||
mood MoodType
|
||||
moodLabel String @map("mood_label")
|
||||
title String?
|
||||
content String
|
||||
marginNotes String[] @default([]) @map("margin_notes")
|
||||
tags String[] @default([])
|
||||
likes Int @default(0)
|
||||
highlightWords String[] @default([]) @map("highlight_words")
|
||||
authorNote String? @map("author_note")
|
||||
imageUrl String? @map("image_url")
|
||||
imageCaption String? @map("image_caption")
|
||||
codeSnippet String? @map("code_snippet")
|
||||
codeLanguage String? @map("code_language")
|
||||
audioDuration String? @map("audio_duration")
|
||||
audioTitle String? @map("audio_title")
|
||||
stampedText String? @map("stamped_text")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("posts")
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
-- mstfyldz Journal PostgreSQL Schema for psql
|
||||
|
||||
-- Create Custom Enum Types (if not existing)
|
||||
DO $$ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'post_type') THEN
|
||||
CREATE TYPE post_type AS ENUM ('notebook', 'sticky', 'polaroid', 'code', 'audio');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'mood_type') THEN
|
||||
CREATE TYPE mood_type AS ENUM ('focus', 'night', 'spark', 'calm', 'visual');
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Create Posts Table
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id VARCHAR(255) PRIMARY KEY,
|
||||
type post_type NOT NULL,
|
||||
date VARCHAR(50) NOT NULL,
|
||||
timestamp VARCHAR(50) NOT NULL,
|
||||
mood mood_type NOT NULL,
|
||||
mood_label VARCHAR(100) NOT NULL,
|
||||
title TEXT,
|
||||
content TEXT NOT NULL,
|
||||
margin_notes TEXT[] DEFAULT '{}',
|
||||
tags TEXT[] DEFAULT '{}',
|
||||
likes INT DEFAULT 0 NOT NULL,
|
||||
highlight_words TEXT[] DEFAULT '{}',
|
||||
author_note TEXT,
|
||||
image_url TEXT,
|
||||
image_caption TEXT,
|
||||
code_snippet TEXT,
|
||||
code_language VARCHAR(50),
|
||||
audio_duration VARCHAR(50),
|
||||
audio_title TEXT,
|
||||
stamped_text VARCHAR(100),
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
-- Performance Indexes
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_mood ON posts(mood);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_type ON posts(type);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_created_at ON posts(created_at DESC);
|
||||
@@ -0,0 +1,52 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { INITIAL_POSTS } from "../components/mockData";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log("Seeding database with initial posts...");
|
||||
|
||||
for (const post of INITIAL_POSTS) {
|
||||
await prisma.post.upsert({
|
||||
where: { id: post.id },
|
||||
update: {
|
||||
title: post.title,
|
||||
content: post.content,
|
||||
likes: post.likes,
|
||||
},
|
||||
create: {
|
||||
id: post.id,
|
||||
type: post.type,
|
||||
date: post.date,
|
||||
timestamp: post.timestamp,
|
||||
mood: post.mood as any,
|
||||
moodLabel: post.moodLabel,
|
||||
title: post.title,
|
||||
content: post.content,
|
||||
marginNotes: post.marginNotes || [],
|
||||
tags: post.tags || [],
|
||||
likes: post.likes || 0,
|
||||
highlightWords: post.highlightWords || [],
|
||||
authorNote: post.authorNote,
|
||||
imageUrl: post.imageUrl,
|
||||
imageCaption: post.imageCaption,
|
||||
codeSnippet: post.codeSnippet,
|
||||
codeLanguage: post.codeLanguage,
|
||||
audioDuration: post.audioDuration,
|
||||
audioTitle: post.audioTitle,
|
||||
stampedText: post.stampedText,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
console.log("Seeding completed successfully!");
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error("Error during seeding:", e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user