diff --git a/app/(Main)/[username]/[url]/layout.tsx b/app/(Main)/[username]/[url]/layout.tsx index 1b355d2e..b45216b1 100644 --- a/app/(Main)/[username]/[url]/layout.tsx +++ b/app/(Main)/[username]/[url]/layout.tsx @@ -20,7 +20,8 @@ async function getPostData(username: string, url: string) { url: url, author: { username: decodedUsername.substring(1) - } + }, + published: true, }, include: { tags: { @@ -50,11 +51,11 @@ async function getPostData(username: string, url: string) { return { metadataBase: new URL(`${process.env.DOMAIN}/@${post.author.username}/${post.url}`), title: `${post.title} - FalseNotes`, - description: post.subtitle || markdownToText(post.content.slice(0, 100)), + description: post.subtitle || markdownToText(post.content?.slice(0, 100) || ''), keywords: post.tags.map((tag: any) => tag.tag.name).join(', '), openGraph: { title: `${post.title} - FalseNotes`, - description: post.subtitle || markdownToText(post.content.slice(0, 100)), + description: post.subtitle || markdownToText(post.content?.slice(0, 100) || ''), url: new URL(`${process.env.DOMAIN}/@${post.author.username}/${post.url}`), images: [ { @@ -68,8 +69,7 @@ async function getPostData(username: string, url: string) { twitter: { card: 'summary_large_image', title: `${post.title} - FalseNotes`, - description: post.subtitle || markdownToText(post.content.slice(0, 100)), - + description: post.subtitle || markdownToText(post.content?.slice(0, 100) || ''), }, } } catch (error) { @@ -105,7 +105,7 @@ export default async function PostLayout( url: { not: params.url }, - visibility: "public", + published: true, }, include: { _count: { select: { comments: true, savedUsers: true, likes: true } }, @@ -179,7 +179,7 @@ export default async function PostLayout( url: { not: post?.url }, - visibility: "public", + published: true, }, include: { _count: { select: { comments: true, savedUsers: true, likes: true } }, diff --git a/app/(Main)/[username]/[url]/page.tsx b/app/(Main)/[username]/[url]/page.tsx index 20fc7fed..dd5c0f59 100644 --- a/app/(Main)/[username]/[url]/page.tsx +++ b/app/(Main)/[username]/[url]/page.tsx @@ -4,6 +4,9 @@ import { notFound } from "next/navigation" import postgres from "@/lib/postgres" import Post from "@/components/blog/post" import { cookies } from 'next/headers' +import { ObjectId } from 'bson'; + +const id = new ObjectId().toHexString(); export default async function PostView({ params, searchParams }: { params: { username: string, url: string }, searchParams: { [key: string]: string | string[] | undefined } }) { const commentsOpen = typeof searchParams.commentsOpen === 'string' ? searchParams.commentsOpen : undefined @@ -67,7 +70,7 @@ export default async function PostView({ params, searchParams }: { params: { use const sessionUser = await getSessionUser() if (post?.authorId !== sessionUser?.id) { - if (post?.visibility !== "public") return notFound(); + if (post?.published) return notFound(); } const published = sessionUser?.id === post?.authorId && ( @@ -93,6 +96,7 @@ export default async function PostView({ params, searchParams }: { params: { use if (!hasReaded) { await postgres.readingHistory.create({ data: { + id, postId: post?.id, userId: sessionUser?.id } diff --git a/app/(Main)/[username]/page.tsx b/app/(Main)/[username]/page.tsx index a55d0a0e..adf8bc6f 100644 --- a/app/(Main)/[username]/page.tsx +++ b/app/(Main)/[username]/page.tsx @@ -52,7 +52,7 @@ export default async function Page({ params, searchParams }: { where: { OR: [ { - visibility: "public", + published: true, }, { authorId: sessionUserName?.id, diff --git a/app/(Main)/page.tsx b/app/(Main)/page.tsx index cd19a5d2..33741e33 100644 --- a/app/(Main)/page.tsx +++ b/app/(Main)/page.tsx @@ -22,7 +22,7 @@ export default async function Home() { const [latestPosts, tags, popularPosts] = await Promise.all([ postgres.post.findMany({ where: { - visibility: 'public', + published: true, }, orderBy: { createdAt: 'desc', diff --git a/app/(Main)/tags/[tagname]/page.tsx b/app/(Main)/tags/[tagname]/page.tsx index f33fdda2..c7aed88f 100644 --- a/app/(Main)/tags/[tagname]/page.tsx +++ b/app/(Main)/tags/[tagname]/page.tsx @@ -22,7 +22,7 @@ export default async function TagPage({ params }: { params: { tagname: string } const popularPosts = await postgres.post.findMany({ where: { - visibility: 'public', + published: true, tags: { some: { tagId: tag?.id @@ -51,7 +51,7 @@ export default async function TagPage({ params }: { params: { tagname: string } }); const latestPosts = await postgres.post.findMany({ where: { - visibility: 'public', + published: true, tags: { some: { tagId: tag?.id diff --git a/app/api/comments/[id]/route.ts b/app/api/comments/[id]/route.ts index 752e64f8..48db510d 100644 --- a/app/api/comments/[id]/route.ts +++ b/app/api/comments/[id]/route.ts @@ -1,5 +1,6 @@ import { create } from "@/lib/notifications/create-notification"; import postgres from "@/lib/postgres"; +import { Comment } from "@prisma/client"; import { NextRequest, NextResponse } from "next/server"; export async function POST(req: NextRequest, { params }: { params: { id: string } }) { @@ -13,7 +14,7 @@ export async function POST(req: NextRequest, { params }: { params: { id: string await postgres.comment.update({ where: { - id: Number(params.id), + id: params.id, }, data: { content: content, @@ -32,7 +33,7 @@ export async function DELETE(req: NextRequest, { params }: { params: { id: strin try { const replies = await postgres.comment.findMany({ where: { - parentId: Number(params.id), + parentId: params.id, }, select: { id: true, @@ -41,7 +42,7 @@ export async function DELETE(req: NextRequest, { params }: { params: { id: strin replies.forEach((reply) => deleteComment(reply)); - await deleteComment(Number(params.id)); + await deleteComment(params.id); return new NextResponse("Comment deleted", { status: 200 }); } catch (error) { @@ -50,10 +51,10 @@ export async function DELETE(req: NextRequest, { params }: { params: { id: strin } } -async function deleteComment(id: number) { +async function deleteComment(id: Comment["id"]) { await postgres.commentLike.deleteMany({ where: { - commentId: Number(id), + commentId: id, }, }) await postgres.commentLike.deleteMany({ @@ -61,7 +62,7 @@ async function deleteComment(id: number) { commentId: { in: await postgres.comment.findMany({ where: { - parentId: Number(id), + parentId: id, }, select: { id: true, @@ -72,14 +73,14 @@ async function deleteComment(id: number) { }) await postgres.comment.deleteMany({ where: { - parentId: Number(id), + parentId: id, }, }) await postgres.comment.delete({ where: { - id: Number(id), + id: id, }, }) } \ No newline at end of file diff --git a/app/api/comments/create/route.ts b/app/api/comments/create/route.ts index 92c008e8..acd936de 100644 --- a/app/api/comments/create/route.ts +++ b/app/api/comments/create/route.ts @@ -1,5 +1,6 @@ import { create } from "@/lib/notifications/create-notification"; import postgres from "@/lib/postgres"; +import { ObjectId } from "bson"; import { NextRequest, NextResponse } from "next/server"; export async function POST(req: NextRequest, res: NextResponse) { @@ -18,6 +19,7 @@ export async function POST(req: NextRequest, res: NextResponse) { // `; await postgres.comment.create({ data: { + id: new ObjectId().toHexString(), content: content, authorId: author, postId: post, diff --git a/app/api/comments/reply/route.ts b/app/api/comments/reply/route.ts index ec8c9987..1148052d 100644 --- a/app/api/comments/reply/route.ts +++ b/app/api/comments/reply/route.ts @@ -1,5 +1,6 @@ import { create } from "@/lib/notifications/create-notification"; import postgres from "@/lib/postgres"; +import { ObjectId } from "bson"; import { NextRequest, NextResponse } from "next/server"; export async function POST(req: NextRequest, res: NextResponse) { @@ -13,6 +14,7 @@ export async function POST(req: NextRequest, res: NextResponse) { await postgres.comment.create({ data: { + id: new ObjectId().toHexString(), content: content, authorId: author, postId: post, @@ -37,7 +39,6 @@ export async function POST(req: NextRequest, res: NextResponse) { author: { select: { username: true, - } } }, diff --git a/app/api/feed/route.ts b/app/api/feed/route.ts deleted file mode 100644 index f6b84302..00000000 --- a/app/api/feed/route.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { config } from '@/app/auth' -import postgres from '@/lib/postgres' -import { getFeed } from '@/lib/prisma/feed'; -import { getServerSession } from 'next-auth' -import { NextRequest, NextResponse } from 'next/server' - -export async function GET(req: NextRequest) { - const pageString = req.nextUrl.searchParams.get('page') || 0 - const page = Number(pageString) - const tag = req.nextUrl.searchParams.get('tag') as string | undefined - const session = await getServerSession(config) - if (!session) { - return NextResponse.json({ error: 'No user found' }, { status: 500 }) - } - const user = session?.user - const res = await postgres.user.findFirst({ - where: { image: user?.image }, - select: { id: true }, - }) - const id = res?.id - if (!id) { - return NextResponse.json({ error: 'No user found' }, { status: 500 }) - } - - const feed = await getFeed({ page, tab: tag, limit: 10 }); - if (feed?.error) { - return NextResponse.json({ error: feed.error }, { status: 500 }); - } else if (feed?.feed) { - return NextResponse.json({ feed: feed.feed }, { status: 200 }); - } -} \ No newline at end of file diff --git a/app/api/follow/route.ts b/app/api/follow/route.ts index 4db18016..ff1def35 100644 --- a/app/api/follow/route.ts +++ b/app/api/follow/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import postgres from "@/lib/postgres"; import { create } from "@/lib/notifications/create-notification"; +import { ObjectId } from "bson"; export async function GET(request: NextRequest) { try { @@ -33,6 +34,7 @@ export async function GET(request: NextRequest) { } else { await postgres.follow.create({ data: { + id: new ObjectId().toHexString(), followerId: followerId, followingId: followeeId, }, diff --git a/app/api/follow/tag/route.ts b/app/api/follow/tag/route.ts index 86c9f54f..6ec90cc1 100644 --- a/app/api/follow/tag/route.ts +++ b/app/api/follow/tag/route.ts @@ -1,8 +1,9 @@ import postgres from "@/lib/postgres" +import { ObjectId } from "bson"; import { NextRequest, NextResponse } from "next/server"; export async function GET(request: NextRequest){ - const tagid = Number(request.nextUrl.searchParams.get("tagId")) + const tagid = request.nextUrl.searchParams.get("tagId") const userid = request.nextUrl.searchParams.get("userId") try { @@ -37,6 +38,7 @@ export async function GET(request: NextRequest){ } else { await postgres.tagFollow.create({ data: { + id: new ObjectId().toHexString(), tagId: tagid, followerId: userid } diff --git a/app/api/notifications/route.ts b/app/api/notifications/route.ts index bed90bca..22047453 100644 --- a/app/api/notifications/route.ts +++ b/app/api/notifications/route.ts @@ -1,4 +1,5 @@ import postgres from "@/lib/postgres" +import { ObjectId } from "bson" import { NextRequest, NextResponse } from "next/server" export async function POST(request: NextRequest) { @@ -11,6 +12,7 @@ export async function POST(request: NextRequest) { await postgres.notification.create({ data: { + id: new ObjectId().toHexString(), content, receiverId, type, @@ -58,14 +60,14 @@ export async function GET(request: NextRequest) { // PUT /api/notifications?id export async function PUT(request: NextRequest) { - const id = await request.nextUrl.searchParams.get("id") + const id = await request.nextUrl.searchParams.get("id")?.toString() try { // await sql` // UPDATE notifications SET readat = ${new Date().toISOString()} WHERE id = ${id} // ` await postgres.notification.update({ where: { - id: Number(id) + id: id }, data: { read: true @@ -80,11 +82,11 @@ export async function PUT(request: NextRequest) { // DELETE /api/notifications?id export async function DELETE(request: NextRequest) { - const id = await request.nextUrl.searchParams.get("id") + const id = await request.nextUrl.searchParams.get("id")?.toString() try { await postgres.notification.delete({ where: { - id: Number(id) + id: id } }) return NextResponse.json({ status: 200, message: "Notification deleted" }) diff --git a/app/api/post/[postid]/drafts/route.ts b/app/api/post/[postid]/drafts/route.ts index 59fdc923..2cc8a9af 100644 --- a/app/api/post/[postid]/drafts/route.ts +++ b/app/api/post/[postid]/drafts/route.ts @@ -1,6 +1,7 @@ import { getSessionUser } from "@/components/get-session-user"; import { insertTag } from "@/lib/insert-tag"; import postgres from "@/lib/postgres"; +import { ObjectId } from "bson"; import { NextRequest } from "next/server"; import readingTime from "reading-time"; import { z } from "zod"; @@ -74,17 +75,16 @@ export async function PATCH( title, content, cover: coverImage || null, - readingTime: readTime, subtitle: subtitle || null, }, }); } else { await postgres.draftPost.create({ data: { + id: new ObjectId().toHexString(), title, content, cover: coverImage || null, - readingTime: readTime, url, subtitle: subtitle || null, postId: postid, diff --git a/app/api/post/[postid]/route.ts b/app/api/post/[postid]/route.ts index 7a7f4cff..b11622b3 100644 --- a/app/api/post/[postid]/route.ts +++ b/app/api/post/[postid]/route.ts @@ -24,7 +24,7 @@ export async function PATCH( title, content, coverImage, - visibility, + published, tags, url, authorId, @@ -45,9 +45,9 @@ export async function PATCH( id: postid, }, select: { - visibility: true, + published: true, }, - }) + }); await postgres.post.update({ where: { @@ -57,14 +57,14 @@ export async function PATCH( title: title, content: content, cover: coverImage || null, - visibility: visibility, + published: published, url: url, subtitle: subtitle || null, readingTime: readTime, - ...(oldData?.visibility === "draft" && - visibility === "public" && { createdAt: new Date() }), - ...(oldData?.visibility === "public" && - visibility === "public" && { updatedAt: new Date(), updated: true }), + ...(oldData?.published === false && + published === true && { publishedAt: new Date() }), + ...(oldData?.published === true && + published === true && { updatedAt: new Date(), updated: true }), }, }); diff --git a/app/api/posts/route.ts b/app/api/posts/route.ts index d721359c..8bb7cfac 100644 --- a/app/api/posts/route.ts +++ b/app/api/posts/route.ts @@ -4,6 +4,9 @@ import postgres from "@/lib/postgres"; import { getServerSession } from "next-auth"; import { NextRequest, NextResponse } from "next/server"; import { z } from "zod"; +import { ObjectId } from 'bson'; + +const id = new ObjectId().toHexString(); const baseQuery = { include: { @@ -54,9 +57,9 @@ export async function GET(req: NextRequest) { contains: search, mode: "insensitive", }, - visibility: "public", + published: true, } - : { visibility: "public" }, + : { published: true }, take: limit, skip: page * limit, }); @@ -93,11 +96,11 @@ export async function POST(req: Request) { const post = await postgres.post.create({ data: { + id: id, title: json.title, content: json.content, authorId: session.id, url: json.url, - visibility: json.visibility, }, select: { id: true, diff --git a/app/api/posts/submit/route.ts b/app/api/posts/submit/route.ts deleted file mode 100644 index d94bbeff..00000000 --- a/app/api/posts/submit/route.ts +++ /dev/null @@ -1,156 +0,0 @@ -import { NextRequest, NextResponse } from "next/server"; -import postgres from "@/lib/postgres" -import readingTime from "reading-time"; - -async function insertTag(tags: any, postid: any) { - if (tags) { - for (const tag of tags) { - // Check if tag exists - const tagExists = await postgres.tag.findFirst({ - where: { - name: tag.value.replace(/\s+/g, '-').toLowerCase(), - }, - }) - if (!tagExists) { - await postgres.tag.create({ - data: { - name: tag.value.replace(/\s+/g, '-').toLowerCase(), - } - }) - } - const tagId = await postgres.tag.findFirst({ - where: { - name: tag.value.replace(/\s+/g, '-').toLowerCase(), - }, - select: { - id: true, - } - }) - if (tagId) { - await postgres.postTag.create({ - data: { - tagId: tagId.id, - postId: postid, - } - }) - } - } - } -} - -export async function POST(req: NextRequest) { - try { - const data = await req.json(); - if (!data) { - return new Response("No data provided", { status: 400 }); - } - const postid = req.nextUrl.searchParams.get("postId"); - - const { title, content, coverImage, visibility, tags, url, authorId, subtitle } = data; - const stats = readingTime(content); - const readTime = stats.text; - - if (!title) { - return new Response("No title provided", { status: 400 }); - } - if (!content) { - return new Response("No content provided", { status: 400 }); - } - - if (!authorId) { - return new Response("No author provided", { status: 400 }); - } - - if (!url) { - return new Response("No url provided", { status: 400 }); - } - - if (postid) { - const postData = await postgres.post.findFirst({ - where: { - id: postid, - }, - }) - if (!postData) { - return new Response("Post does not exist", { status: 400 }); - } - - if (title !== postData.title || content !== postData.content || coverImage !== postData.cover || visibility !== postData.visibility || url !== postData.url || subtitle !== postData.subtitle, readTime !== postData.readingTime) { - - await postgres.post.update({ - where: { - id: postid, - }, - data: { - title: title, - content: content, - cover: coverImage, - visibility: visibility, - url: url, - subtitle: subtitle, - readingTime: readTime, - updated: true, - } - }) - - } - const postTagsData = await postgres.postTag.findMany({ - where: { - postId: postid, - }, - select: { - tag: { - select: { - name: true, - } - } - } - }) - if (postTagsData) { - await postgres.postTag.deleteMany({ - where: { - postId: postid, - } - }) - } - await insertTag(tags, postid); - - - return NextResponse.json({ body: "Post updated" }); - } - else { - await postgres.post.create({ - data: { - title: title, - content: content, - cover: coverImage ? coverImage : null, - visibility: visibility, - url: url, - subtitle: subtitle ? subtitle : null, - authorId: authorId, - readingTime: readTime, - } - }) - - const submittedPostId = await postgres.post.findFirst({ - where: { - url: url, - }, - select: { - id: true, - } - }) - - const postId = submittedPostId?.id; - - await insertTag(tags, postId); - - return NextResponse.json({ body: "Post submitted" }); - } - } catch (error) { - console.error("Error:", error); - return NextResponse.json({body: "Error processing data"}, - {status: 500}); - } - } - \ No newline at end of file diff --git a/app/api/user/[id]/posts/route.ts b/app/api/user/[id]/posts/route.ts index d076b464..ac1997c2 100644 --- a/app/api/user/[id]/posts/route.ts +++ b/app/api/user/[id]/posts/route.ts @@ -33,9 +33,9 @@ export async function GET(req: NextRequest, { params } : { params: { id: string const posts = await postgres.post.findMany({ ...baseQuery, where: { - ...(session?.id === userId ? {} : { visibility: "public" }), + ...(session?.id === userId ? {} : { published: true }), authorId: userId, - visibility: session?.id === userId ? undefined : "public", + published: session?.id === userId ? undefined : true, ...(search ? { title: { contains: search, mode: "insensitive" } } : {}), }, take: Number(limit), diff --git a/app/auth.ts b/app/auth.ts index dd235ad1..1d5e7f97 100644 --- a/app/auth.ts +++ b/app/auth.ts @@ -2,6 +2,9 @@ import postgres from "@/lib/postgres" import type { NextAuthOptions as NextAuthConfig } from "next-auth" import GitHub from "next-auth/providers/github" import { PrismaAdapter } from "@next-auth/prisma-adapter" +import { ObjectId } from 'bson'; + +const id = new ObjectId().toHexString(); export const config = { // https://next-auth.js.org/configuration/providers/oauth @@ -42,6 +45,7 @@ export const config = { try { const sessionUser = await postgres.user.create({ data: { + id: id, username: username, name: name, email: email, @@ -64,6 +68,7 @@ export const config = { if (!userSettingsExists) { await postgres.userSettings.create({ data: { + id: new ObjectId().toHexString(), userId: sessionUser.id } }) diff --git a/app/editor/[id]/page.tsx b/app/editor/[id]/page.tsx index 708664aa..4853df11 100644 --- a/app/editor/[id]/page.tsx +++ b/app/editor/[id]/page.tsx @@ -34,7 +34,6 @@ async function getPostForUser(postId: Post['id']) { post.title = draft.title post.subtitle = draft.subtitle post.cover = draft.cover - post.readingTime = draft.readingTime } return post diff --git a/components/blog/post.tsx b/components/blog/post.tsx index e0db8513..dec8178e 100644 --- a/components/blog/post.tsx +++ b/components/blog/post.tsx @@ -134,7 +134,7 @@ export default function SinglePost({ post: initialPost, author, sessionUser, tag
{post?.readingTime} ยท - {dateFormat(post?.createdAt)} + {dateFormat(post?.publishedAt)} { post?.updated && ( <> diff --git a/components/blog/publish-dialog.tsx b/components/blog/publish-dialog.tsx index 9cc482e5..c5b975dd 100644 --- a/components/blog/publish-dialog.tsx +++ b/components/blog/publish-dialog.tsx @@ -45,47 +45,48 @@ export default function PublishDialog({ post, user, session, ...props }: { post:
- - - {post.title} - - - {post.subtitle} - - -
-
- {post.cover && ( + + + {post.title} + + + {post.subtitle} + + + {post.cover && (
+
+ {post.title} - )} + +
-
+ )}
-
-

{post.readingTime}

-
-
-
- -
-
- -
-
-
+
+

{post.readingTime}

+
+
+
+ +
+
+ +
+
+
diff --git a/components/bookmark.ts b/components/bookmark.ts index 63adf408..d677fd66 100644 --- a/components/bookmark.ts +++ b/components/bookmark.ts @@ -1,40 +1,48 @@ -'use server' -import postgres from "@/lib/postgres" -import { getSessionUser } from "./get-session-user" -import { revalidatePath } from "next/cache" +"use server"; +import postgres from "@/lib/postgres"; +import { getSessionUser } from "./get-session-user"; +import { revalidatePath } from "next/cache"; +import { ObjectId } from "bson"; -export const handlePostSave = async ({ postId, path} : {postId: string, path: string}) => { - const sessionUser = await getSessionUser() - if (!sessionUser) { - console.log("No session user") - } - try { - const saved = await postgres.bookmark.findFirst({ - where: { - postId, - userId: sessionUser?.id - } - }) +export const handlePostSave = async ({ + postId, + path, +}: { + postId: string; + path: string; +}) => { + const sessionUser = await getSessionUser(); + if (!sessionUser) { + console.log("No session user"); + } + try { + const saved = await postgres.bookmark.findFirst({ + where: { + postId, + userId: sessionUser?.id, + }, + }); - if (sessionUser?.id) { - if (saved) { - await postgres.bookmark.delete({ - where: { - id: saved.id - } - }) - } else { - await postgres.bookmark.create({ - data: { - userId: sessionUser.id, - postId - } - }) - } - - revalidatePath(path) - } - } catch (error) { - console.log(error) - } -} \ No newline at end of file + if (sessionUser?.id) { + if (saved) { + await postgres.bookmark.delete({ + where: { + id: saved.id, + }, + }); + } else { + await postgres.bookmark.create({ + data: { + id: new ObjectId().toHexString(), + userId: sessionUser.id, + postId, + }, + }); + } + + revalidatePath(path); + } + } catch (error) { + console.log(error); + } +}; diff --git a/components/editor/post-editor-form.tsx b/components/editor/post-editor-form.tsx index db348855..fd6bb4d2 100644 --- a/components/editor/post-editor-form.tsx +++ b/components/editor/post-editor-form.tsx @@ -81,9 +81,6 @@ const postFormSchema = z.object({ .max(100, { message: "Username must not be longer than 100 characters.", }), - visibility: z.enum(["public", "private", "draft"], { - required_error: "Please select a visibility option", - }), content: z.string(), coverImage: z.string().optional(), tags: z @@ -97,12 +94,13 @@ const postFormSchema = z.object({ .optional(), url: z.string(), subtitle: z.string().max(280, { message: "Subtitle must not be longer than 280 characters." }).optional(), + published: z.boolean().optional(), }) type PostFormValues = z.infer export function PostEditorForm(props: { post: any, user: any }) { - const [previousStatus, setPreviousStatus] = useState(props.post?.visibility); + const [previousStatus, setPreviousStatus] = useState(props.post?.published); const router = useRouter(); const [markdownContent, setMarkdownContent] = useState(props.post?.content); @@ -111,10 +109,10 @@ export function PostEditorForm(props: { post: any, user: any }) { id: props.post?.id, title: props.post?.title, content: props.post?.content, - visibility: props.post?.visibility, coverImage: props.post?.cover || '', url: props.post?.url, subtitle: props.post?.subtitle || '', + published: props.post?.published, tags: props.post?.tags?.map((tag: any) => ({ value: tag.tag?.name, })), @@ -166,7 +164,7 @@ export function PostEditorForm(props: { post: any, user: any }) { } await validate(`/@${props.user?.username}`) - if (data.visibility === 'public' && previousStatus !== 'public') { + if (data.published == true && previousStatus == false) { router.push(`/@${props.user?.username}/${form.getValues('url')}?published=true`); toast({ description: "Post Published!" }); } @@ -385,46 +383,6 @@ export function PostEditorForm(props: { post: any, user: any }) { Post Settings for publishing
- ( - - Privacy - - - - - - - - Public - - - - - - - - Private - - - - - - - Draft - - - - - - )} - /> { + form.setValue('published', true); + } + } > { isPublishing ? ( <> - Publishing + {previousStatus ? 'Updating' : 'Publishing'} ) : ( - <>Publish + <>{ previousStatus ? 'Update' : 'Publish' } ) } @@ -701,7 +663,6 @@ export function PostEditorForm(props: { post: any, user: any }) { }) } if (form.getValues('content') !== undefined && form.getValues('title') !== undefined) { - form.setValue('visibility', 'public'); setOpen(true); } } diff --git a/components/feed/feed.tsx b/components/feed/feed.tsx index 12eafa04..0d3c1db5 100644 --- a/components/feed/feed.tsx +++ b/components/feed/feed.tsx @@ -39,7 +39,9 @@ export default function InfinitiveScrollFeed({ initialFeed, tag, session }: { in } }, [inView]) - return feed.length > 0 ? ( + const safeFeed = feed || []; + + return safeFeed.length > 0 ? (
diff --git a/components/get-session-user.ts b/components/get-session-user.ts index e5010861..ef6bb4c7 100644 --- a/components/get-session-user.ts +++ b/components/get-session-user.ts @@ -30,4 +30,4 @@ async function fetchSessionUser() { } } -export const getSessionUser = cache(fetchSessionUser) \ No newline at end of file +export const getSessionUser = async () => await fetchSessionUser(); \ No newline at end of file diff --git a/components/like.ts b/components/like.ts index 84fac13b..6654896d 100644 --- a/components/like.ts +++ b/components/like.ts @@ -3,6 +3,8 @@ import postgres from "@/lib/postgres" import { getSessionUser } from "./get-session-user" import { revalidatePath } from "next/cache" import { create } from "@/lib/notifications/create-notification" +import { ObjectId } from "bson" +import { Comment } from "@prisma/client" export const handlePostLike = async ({ postId, path} : {postId: string, path: string}) => { const sessionUser = await getSessionUser() @@ -27,6 +29,7 @@ export const handlePostLike = async ({ postId, path} : {postId: string, path: st } else { const data = await postgres.like.create({ data: { + id: new ObjectId().toHexString(), authorId: sessionUser.id, postId }, @@ -57,7 +60,7 @@ export const handlePostLike = async ({ postId, path} : {postId: string, path: st } } -export const handleCommentLike = async ({ commentId, path} : {commentId: number, path: string}) => { +export const handleCommentLike = async ({ commentId, path} : {commentId: Comment['id'], path: string}) => { const sessionUser = await getSessionUser() if (!sessionUser) { console.log("No session user") @@ -81,6 +84,7 @@ export const handleCommentLike = async ({ commentId, path} : {commentId: number, } else { const data = await postgres.commentLike.create({ data: { + id: new ObjectId().toHexString(), authorId: sessionUser?.id, commentId }, diff --git a/components/navbar/post-create-button.tsx b/components/navbar/post-create-button.tsx index 367f0ec0..1f622e81 100644 --- a/components/navbar/post-create-button.tsx +++ b/components/navbar/post-create-button.tsx @@ -31,7 +31,6 @@ export function PostCreateButton({ body: JSON.stringify({ title: "Untitled Post", content: "", - visibility: "draft", url: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15), }), }) diff --git a/components/tags/post-card-v2.tsx b/components/tags/post-card-v2.tsx index 71846591..df2a4fcc 100644 --- a/components/tags/post-card-v2.tsx +++ b/components/tags/post-card-v2.tsx @@ -73,7 +73,7 @@ export default function PostCard( props.user == 'true' && ( props.session?.id === props.post.author?.id && ( - {props.post.visibility} + {props.post.published === false ? "Draft" : "Published"} ) ) @@ -85,7 +85,7 @@ export default function PostCard(
- +

{props.post.title}

@@ -144,7 +144,7 @@ export default function PostCard(
{props.post.cover && (
- +
<> { return postgres.post.findMany({ where: { - visibility: "public", + published: true, }, select: { title: true, diff --git a/lib/insert-tag.ts b/lib/insert-tag.ts index 877c156e..c388e828 100644 --- a/lib/insert-tag.ts +++ b/lib/insert-tag.ts @@ -1,5 +1,6 @@ import { Post, Tag } from "@prisma/client"; import postgres from "./postgres"; +import { ObjectId } from "bson"; function sanitizeTagName(tag: string): string { //if tag is "hello world" it will be "hello-world" if 'hello world ' it will be 'hello-world' not 'hello-world-' @@ -25,7 +26,10 @@ export async function insertTag(tags: any, postid: string) { }); if (!tagExists) { const tagId = await postgres.tag.create({ - data: { name: tag }, + data: { + id: new ObjectId().toHexString(), + name: tag + }, select: { id: true }, }); await connectTagToPost(tagId.id, postid); @@ -51,6 +55,7 @@ async function connectTagToPost(tagId: Tag['id'], postid: Post['id']) { if (!tagAlreadyConnected) { await postgres.postTag.create({ data: { + id: new ObjectId().toHexString(), tagId: tagId, postId: postid, }, diff --git a/lib/notifications/create-notification.tsx b/lib/notifications/create-notification.tsx index 9489d731..88fb1f9e 100644 --- a/lib/notifications/create-notification.tsx +++ b/lib/notifications/create-notification.tsx @@ -1,3 +1,4 @@ +import { ObjectId } from "bson"; import postgres from "../postgres"; type NotificationData = { @@ -13,6 +14,7 @@ export const create = async (data: NotificationData) => { console.log(data) await postgres.notification.create({ data: { + id: new ObjectId().toHexString(), type: data.type, content: data.content, receiverId: data.receiverId, diff --git a/lib/prisma/feed.ts b/lib/prisma/feed.ts index 83a37032..81cd9862 100644 --- a/lib/prisma/feed.ts +++ b/lib/prisma/feed.ts @@ -1,6 +1,7 @@ 'use server' import { getSessionUser } from "@/components/get-session-user"; import postgres from "../postgres"; +import { ObjectId } from "bson"; const getLikes = async ({ id }: { id: string | undefined }) => { const likes = await postgres.like.findMany({ @@ -82,7 +83,7 @@ const baseQuery = { subtitle: true, url: true, cover: true, - visibility: true, + published: true, createdAt: true, updatedAt: true, readingTime: true, @@ -155,17 +156,20 @@ const tagCounts = tags.reduce((counts, tag) => { }, {} as Record); // Sort the tags by their count in descending order -const sortedTagIds = Object.entries(tagCounts).sort((a, b) => b[1] - a[1]).map(([tagId]) => Number(tagId)); - -const posts = await postgres.post.findMany({ - where: { tags: { some: { tagId: { in: sortedTagIds.slice(0, 5) } } } }, - select: { id: true }, -}); +const sortedTagIds = Object.entries(tagCounts) + .sort((a, b) => b[1] - a[1]) + .map(([tagId]) => Number(tagId).toString()); // Convert numbers to strings + + const validTagIds = sortedTagIds.filter(tagId => ObjectId.isValid(tagId)); + const posts = await postgres.post.findMany({ + where: { tags: { some: { tagId: { in: validTagIds.slice(0, 5) } } } }, + select: { id: true }, + }); // remove duplicates const uniquePosts = posts.filter((post, index) => posts.findIndex((p) => p.id === post.id) === index); return fetchFeed({ - where: { id: { in: uniquePosts.map((post) => post.id) }, visibility: "public" }, + where: { id: { in: uniquePosts.map((post) => post.id) }, published: true }, ...baseQuery, take: Number(limit), skip: page * Number(limit), @@ -202,7 +206,7 @@ export const getFeed = async ({ page = 0, tab, limit = 10 }: { page?: number | u ...baseQuery, take: Number(limit), skip: page * Number(limit), - where: { authorId: { in: followingIds }, visibility: "public" }, + where: { authorId: { in: followingIds }, published: true }, select: { ...baseQuery.select, author: { @@ -223,7 +227,7 @@ export const getFeed = async ({ page = 0, tab, limit = 10 }: { page?: number | u ...baseQuery, take: Number(limit), skip: page * Number(limit), - where: { id: { in: postIds }, visibility: "public" }, + where: { id: { in: postIds }, published: true }, }); } }; \ No newline at end of file diff --git a/lib/prisma/get-comment.ts b/lib/prisma/get-comment.ts index 7b975bab..2d81963a 100644 --- a/lib/prisma/get-comment.ts +++ b/lib/prisma/get-comment.ts @@ -1,8 +1,9 @@ 'use server' +import { Comment } from "@prisma/client" import postgres from "../postgres" -export const getComment = async (id: number) => { +export const getComment = async (id: Comment['id']) => { return await postgres.comment.findUnique({ where: { id: id diff --git a/lib/prisma/posts.ts b/lib/prisma/posts.ts index 700fb30f..6880d971 100644 --- a/lib/prisma/posts.ts +++ b/lib/prisma/posts.ts @@ -59,9 +59,9 @@ export const getPosts = async ({ contains: search, mode: "insensitive", }, - visibility: "public", + published: true, } - : { visibility: "public" }, + : { published: true }, take: limit, skip: page * limit, orderBy: [ diff --git a/migrations/20231019202651_init-db.ts b/migrations/20231019202651_init-db.ts deleted file mode 100644 index c23f417e..00000000 --- a/migrations/20231019202651_init-db.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { Knex } from "knex"; - - -export async function up(knex: Knex): Promise { - await knex.schema.createTable("accounts", (table) => { - table.increments("id").primary(); - table.integer("user_id").notNullable(); - table.string("type"); - table.string("provider").unique(); - table.string("provider_account_id").unique(); - table.string("refresh_token").notNullable(); - table.string("access_token").notNullable(); - table.integer("expires_at").notNullable(); - table.string("token_type").notNullable(); - table.string("scope").notNullable(); - table.text("id_token").notNullable(); - table.string("session_state").notNullable(); - }) - await knex.schema.createTable("sessions", (table) => { - table.increments("id").primary(); - table.string("session_token").unique(); - table.string("user_id"); - table.dateTime("expires"); - }) - await knex.schema.createTable("verificationtokens", (table) => { - table.string("identifier").unique(); - table.string("token").unique(); - table.dateTime("expires"); - }) - await knex.schema.createTable("users", (table) => { - table.increments("id").primary(); - table.string("name"); - table.string("username").notNullable().unique(); - table.string("bio"); - table.string("email"); - table.dateTime("email_verified"); - table.string("image").notNullable(); - table.string("password"); - table.string("githubprofile"); - table.string("location"); - table.boolean("verified").defaultTo(false); - table.string("verificationtoken"); - table.boolean("falsemember").defaultTo(false); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - await knex.schema.createTable("posts", (table) => { - table.increments("id").primary(); - table.string("title").notNullable(); - table.text("content").notNullable(); - table.string("subtitle"); - table.string("cover"); - table.integer("authorId").unsigned().notNullable(); - table.foreign("authorId").references("users.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - table.string("url").notNullable().unique(); - table.string("visibility").defaultTo("public"); - table.boolean("updated").defaultTo(false); - table.integer("views").defaultTo(0); - }); - - await knex.schema.createTable("comments", (table) => { - table.increments("id").primary(); - table.text("content").notNullable(); - table.integer("authorId").unsigned().notNullable(); - table.foreign("authorId").references("users.id").onDelete("CASCADE"); - table.integer("postId").unsigned().notNullable(); - table.foreign("postId").references("posts.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("likes", (table) => { - table.increments("id").primary(); - table.integer("authorId").unsigned().notNullable(); - table.foreign("authorId").references("users.id").onDelete("CASCADE"); - table.integer("postId").unsigned().notNullable(); - table.foreign("postId").references("posts.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("commentlikes", (table) => { - table.increments("id").primary(); - table.integer("authorId").unsigned().notNullable(); - table.foreign("authorId").references("users.id").onDelete("CASCADE"); - table.integer("commentId").unsigned().notNullable(); - table.foreign("commentId").references("comments.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("tags", (table) => { - table.increments("id").primary(); - table.string("name").notNullable().unique(); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("posttags", (table) => { - table.increments("id").primary(); - table.integer("postId").unsigned().notNullable(); - table.foreign("postId").references("posts.id").onDelete("CASCADE"); - table.integer("tagId").unsigned().notNullable(); - table.foreign("tagId").references("tags.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("follows", (table) => { - table.increments("id").primary(); - table.integer("followerId").unsigned().notNullable(); - table.foreign("followerId").references("users.id").onDelete("CASCADE"); - table.integer("followingId").unsigned().notNullable(); - table.foreign("followingId").references("users.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - } ); - - await knex.schema.createTable("tagfollows", (table) => { - table.increments("id").primary(); - table.integer("tagId").unsigned().notNullable(); - table.foreign("tagId").references("tags.id").onDelete("CASCADE"); - table.integer("followerId").unsigned().notNullable(); - table.foreign("followerId").references("users.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("notifications", (table) => { - table.increments("id").primary(); - table.integer("receiverId").unsigned().notNullable(); - table.foreign("receiverId").references("users.id").onDelete("CASCADE"); - table.string("content").notNullable(); - table.string("type").notNullable(); - table.string("url"); - table.boolean("read").defaultTo(false); - table.integer("senderId").unsigned().notNullable(); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("bookmarks", (table) => { - table.increments("id").primary(); - table.integer("userId").unsigned().notNullable(); - table.foreign("userId").references("users.id").onDelete("CASCADE"); - table.integer("postId").unsigned().notNullable(); - table.foreign("postId").references("posts.id").onDelete("CASCADE"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); - - await knex.schema.createTable("usersettings", (table) => { - table.increments("id").primary(); - table.integer("userId").unsigned().notNullable(); - table.foreign("userId").references("users.id").onDelete("CASCADE"); - table.string("appearance").defaultTo("system"); - table.string("language").defaultTo("en"); - table.timestamp("createdAt").defaultTo(knex.fn.now()); - table.timestamp("updatedAt").defaultTo(knex.fn.now()); - }); -} - - -export async function down(knex: Knex): Promise { - await knex.schema.dropTable("accounts"); - await knex.schema.dropTable("sessions"); - await knex.schema.dropTable("verificationtokens"); - await knex.schema.dropTable("usersettings"); - await knex.schema.dropTable("bookmarks"); - await knex.schema.dropTable("notifications"); - await knex.schema.dropTable("tagfollows"); - await knex.schema.dropTable("follows"); - await knex.schema.dropTable("posttags"); - await knex.schema.dropTable("tags"); - await knex.schema.dropTable("commentlikes"); - await knex.schema.dropTable("likes"); - await knex.schema.dropTable("comments"); - await knex.schema.dropTable("posts"); - await knex.schema.dropTable("users"); -} - diff --git a/package-lock.json b/package-lock.json index 95885d47..342d66b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,7 @@ "@vercel/og": "^0.5.14", "autoprefixer": "10.4.15", "aws-sdk": "^2.1462.0", + "bson": "^6.2.0", "buffer": "^6.0.3", "class-variance-authority": "^0.7.0", "clsx": "^2.0.0", @@ -3476,6 +3477,14 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bson": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz", + "integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==", + "engines": { + "node": ">=16.20.1" + } + }, "node_modules/buffer": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", diff --git a/package.json b/package.json index fcdf23a4..e104a50a 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@vercel/og": "^0.5.14", "autoprefixer": "10.4.15", "aws-sdk": "^2.1462.0", + "bson": "^6.2.0", "buffer": "^6.0.3", "class-variance-authority": "^0.7.0", "clsx": "^2.0.0", diff --git a/prisma/migrations/20231024075127_migration/migration.sql b/prisma/migrations/20231024075127_migration/migration.sql deleted file mode 100644 index 6baf9c72..00000000 --- a/prisma/migrations/20231024075127_migration/migration.sql +++ /dev/null @@ -1,280 +0,0 @@ --- CreateTable -CREATE TABLE "accounts" ( - "id" TEXT NOT NULL, - "user_id" TEXT NOT NULL, - "type" TEXT NOT NULL, - "provider" TEXT NOT NULL, - "provider_account_id" TEXT NOT NULL, - "refresh_token" TEXT, - "access_token" TEXT, - "expires_at" INTEGER, - "token_type" TEXT, - "scope" TEXT, - "id_token" TEXT, - "session_state" TEXT, - - CONSTRAINT "accounts_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "sessions" ( - "id" TEXT NOT NULL, - "session_token" TEXT NOT NULL, - "user_id" TEXT NOT NULL, - "expires" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "sessions_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "verificationtokens" ( - "identifier" TEXT NOT NULL, - "token" TEXT NOT NULL, - "expires" TIMESTAMP(3) NOT NULL -); - --- CreateTable -CREATE TABLE "users" ( - "id" TEXT NOT NULL, - "email" TEXT NOT NULL, - "username" TEXT, - "name" TEXT NOT NULL, - "bio" TEXT NOT NULL, - "password" TEXT NOT NULL, - "email_verified" TIMESTAMP(3), - "image" TEXT, - "githubprofile" TEXT NOT NULL, - "location" TEXT NOT NULL, - "verified" BOOLEAN NOT NULL DEFAULT false, - "falsemember" BOOLEAN NOT NULL DEFAULT false, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "users_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "posts" ( - "id" SERIAL NOT NULL, - "title" TEXT, - "content" TEXT, - "subtitle" VARCHAR(280) NOT NULL, - "cover" TEXT NOT NULL, - "views" INTEGER NOT NULL DEFAULT 0, - "authorId" TEXT NOT NULL, - "url" TEXT, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - "visibility" TEXT NOT NULL DEFAULT 'public', - "updated" BOOLEAN NOT NULL DEFAULT false, - - CONSTRAINT "posts_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "comments" ( - "id" SERIAL NOT NULL, - "content" TEXT NOT NULL, - "authorId" TEXT NOT NULL, - "postId" INTEGER NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "comments_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "likes" ( - "id" SERIAL NOT NULL, - "authorId" TEXT NOT NULL, - "postId" INTEGER NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "likes_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "commentlikes" ( - "id" SERIAL NOT NULL, - "authorId" TEXT NOT NULL, - "commentId" INTEGER NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "commentlikes_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "tags" ( - "id" SERIAL NOT NULL, - "name" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "tags_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "posttags" ( - "id" SERIAL NOT NULL, - "postId" INTEGER NOT NULL, - "tagId" INTEGER NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "posttags_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "follows" ( - "id" SERIAL NOT NULL, - "followerId" TEXT NOT NULL, - "followingId" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "follows_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "tagfollows" ( - "id" SERIAL NOT NULL, - "followerId" TEXT NOT NULL, - "tagId" INTEGER NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "tagfollows_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "notifications" ( - "id" SERIAL NOT NULL, - "content" TEXT NOT NULL, - "read" BOOLEAN NOT NULL DEFAULT false, - "receiverId" TEXT NOT NULL, - "type" TEXT, - "url" TEXT NOT NULL, - "senderId" INTEGER, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "notifications_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "bookmarks" ( - "id" SERIAL NOT NULL, - "postId" INTEGER NOT NULL, - "userId" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "bookmarks_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "usersettings" ( - "id" SERIAL NOT NULL, - "userId" TEXT NOT NULL, - "appearance" TEXT NOT NULL DEFAULT 'system', - "language" TEXT NOT NULL DEFAULT 'en', - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "usersettings_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "accounts_provider_provider_account_id_key" ON "accounts"("provider", "provider_account_id"); - --- CreateIndex -CREATE UNIQUE INDEX "sessions_session_token_key" ON "sessions"("session_token"); - --- CreateIndex -CREATE UNIQUE INDEX "verificationtokens_token_key" ON "verificationtokens"("token"); - --- CreateIndex -CREATE UNIQUE INDEX "verificationtokens_identifier_token_key" ON "verificationtokens"("identifier", "token"); - --- CreateIndex -CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); - --- CreateIndex -CREATE UNIQUE INDEX "users_username_key" ON "users"("username"); - --- CreateIndex -CREATE UNIQUE INDEX "posts_url_key" ON "posts"("url"); - --- CreateIndex -CREATE INDEX "posts_createdAt_idx" ON "posts"("createdAt"); - --- CreateIndex -CREATE INDEX "comments_createdAt_idx" ON "comments"("createdAt"); - --- CreateIndex -CREATE UNIQUE INDEX "tags_name_key" ON "tags"("name"); - --- CreateIndex -CREATE INDEX "notifications_createdAt_idx" ON "notifications"("createdAt"); - --- CreateIndex -CREATE UNIQUE INDEX "usersettings_userId_key" ON "usersettings"("userId"); - --- AddForeignKey -ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "posts" ADD CONSTRAINT "posts_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "comments" ADD CONSTRAINT "comments_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "comments" ADD CONSTRAINT "comments_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "likes" ADD CONSTRAINT "likes_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "likes" ADD CONSTRAINT "likes_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "commentlikes" ADD CONSTRAINT "commentlikes_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "commentlikes" ADD CONSTRAINT "commentlikes_commentId_fkey" FOREIGN KEY ("commentId") REFERENCES "comments"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "posttags" ADD CONSTRAINT "posttags_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "posttags" ADD CONSTRAINT "posttags_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "tags"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "follows" ADD CONSTRAINT "follows_followerId_fkey" FOREIGN KEY ("followerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "follows" ADD CONSTRAINT "follows_followingId_fkey" FOREIGN KEY ("followingId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tagfollows" ADD CONSTRAINT "tagfollows_followerId_fkey" FOREIGN KEY ("followerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tagfollows" ADD CONSTRAINT "tagfollows_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "tags"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "notifications" ADD CONSTRAINT "notifications_receiverId_fkey" FOREIGN KEY ("receiverId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "bookmarks" ADD CONSTRAINT "bookmarks_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "bookmarks" ADD CONSTRAINT "bookmarks_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "usersettings" ADD CONSTRAINT "usersettings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231024123040_/migration.sql b/prisma/migrations/20231024123040_/migration.sql deleted file mode 100644 index 0e63b948..00000000 --- a/prisma/migrations/20231024123040_/migration.sql +++ /dev/null @@ -1,145 +0,0 @@ -/* - Warnings: - - - The primary key for the `users` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The `id` column on the `users` table would be dropped and recreated. This will lead to data loss if there is data in the column. - - Changed the type of `user_id` on the `accounts` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `userId` on the `bookmarks` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `authorId` on the `commentlikes` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `authorId` on the `comments` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `followerId` on the `follows` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `followingId` on the `follows` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `authorId` on the `likes` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `receiverId` on the `notifications` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `authorId` on the `posts` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `user_id` on the `sessions` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `followerId` on the `tagfollows` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `userId` on the `usersettings` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - -*/ --- DropForeignKey -ALTER TABLE "accounts" DROP CONSTRAINT "accounts_user_id_fkey"; - --- DropForeignKey -ALTER TABLE "bookmarks" DROP CONSTRAINT "bookmarks_userId_fkey"; - --- DropForeignKey -ALTER TABLE "commentlikes" DROP CONSTRAINT "commentlikes_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "comments" DROP CONSTRAINT "comments_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "follows" DROP CONSTRAINT "follows_followerId_fkey"; - --- DropForeignKey -ALTER TABLE "follows" DROP CONSTRAINT "follows_followingId_fkey"; - --- DropForeignKey -ALTER TABLE "likes" DROP CONSTRAINT "likes_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "notifications" DROP CONSTRAINT "notifications_receiverId_fkey"; - --- DropForeignKey -ALTER TABLE "posts" DROP CONSTRAINT "posts_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "sessions" DROP CONSTRAINT "sessions_user_id_fkey"; - --- DropForeignKey -ALTER TABLE "tagfollows" DROP CONSTRAINT "tagfollows_followerId_fkey"; - --- DropForeignKey -ALTER TABLE "usersettings" DROP CONSTRAINT "usersettings_userId_fkey"; - --- AlterTable -ALTER TABLE "accounts" DROP COLUMN "user_id", -ADD COLUMN "user_id" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "bookmarks" DROP COLUMN "userId", -ADD COLUMN "userId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "commentlikes" DROP COLUMN "authorId", -ADD COLUMN "authorId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "comments" DROP COLUMN "authorId", -ADD COLUMN "authorId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "follows" DROP COLUMN "followerId", -ADD COLUMN "followerId" INTEGER NOT NULL, -DROP COLUMN "followingId", -ADD COLUMN "followingId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "likes" DROP COLUMN "authorId", -ADD COLUMN "authorId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "notifications" DROP COLUMN "receiverId", -ADD COLUMN "receiverId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "posts" DROP COLUMN "authorId", -ADD COLUMN "authorId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "sessions" DROP COLUMN "user_id", -ADD COLUMN "user_id" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "tagfollows" DROP COLUMN "followerId", -ADD COLUMN "followerId" INTEGER NOT NULL; - --- AlterTable -ALTER TABLE "users" DROP CONSTRAINT "users_pkey", -DROP COLUMN "id", -ADD COLUMN "id" SERIAL NOT NULL, -ADD CONSTRAINT "users_pkey" PRIMARY KEY ("id"); - --- AlterTable -ALTER TABLE "usersettings" DROP COLUMN "userId", -ADD COLUMN "userId" INTEGER NOT NULL; - --- CreateIndex -CREATE UNIQUE INDEX "usersettings_userId_key" ON "usersettings"("userId"); - --- AddForeignKey -ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "posts" ADD CONSTRAINT "posts_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "comments" ADD CONSTRAINT "comments_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "likes" ADD CONSTRAINT "likes_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "commentlikes" ADD CONSTRAINT "commentlikes_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "follows" ADD CONSTRAINT "follows_followerId_fkey" FOREIGN KEY ("followerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "follows" ADD CONSTRAINT "follows_followingId_fkey" FOREIGN KEY ("followingId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tagfollows" ADD CONSTRAINT "tagfollows_followerId_fkey" FOREIGN KEY ("followerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "notifications" ADD CONSTRAINT "notifications_receiverId_fkey" FOREIGN KEY ("receiverId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "bookmarks" ADD CONSTRAINT "bookmarks_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "usersettings" ADD CONSTRAINT "usersettings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231025114347_/migration.sql b/prisma/migrations/20231025114347_/migration.sql deleted file mode 100644 index 45004239..00000000 --- a/prisma/migrations/20231025114347_/migration.sql +++ /dev/null @@ -1,13 +0,0 @@ -/* - Warnings: - - - Made the column `username` on table `users` required. This step will fail if there are existing NULL values in that column. - -*/ --- AlterTable -ALTER TABLE "users" ALTER COLUMN "email" DROP NOT NULL, -ALTER COLUMN "username" SET NOT NULL, -ALTER COLUMN "name" DROP NOT NULL, -ALTER COLUMN "bio" DROP NOT NULL, -ALTER COLUMN "password" DROP NOT NULL, -ALTER COLUMN "location" DROP NOT NULL; diff --git a/prisma/migrations/20231102104005_221102/migration.sql b/prisma/migrations/20231102104005_221102/migration.sql deleted file mode 100644 index c6ef4a08..00000000 --- a/prisma/migrations/20231102104005_221102/migration.sql +++ /dev/null @@ -1,15 +0,0 @@ -/* - Warnings: - - - Made the column `title` on table `posts` required. This step will fail if there are existing NULL values in that column. - - Made the column `content` on table `posts` required. This step will fail if there are existing NULL values in that column. - - Made the column `url` on table `posts` required. This step will fail if there are existing NULL values in that column. - -*/ --- AlterTable -ALTER TABLE "posts" ADD COLUMN "readingTime" VARCHAR(250), -ALTER COLUMN "title" SET NOT NULL, -ALTER COLUMN "content" SET NOT NULL, -ALTER COLUMN "subtitle" DROP NOT NULL, -ALTER COLUMN "cover" DROP NOT NULL, -ALTER COLUMN "url" SET NOT NULL; diff --git a/prisma/migrations/20231106092655_reading_history/migration.sql b/prisma/migrations/20231106092655_reading_history/migration.sql deleted file mode 100644 index 4db06264..00000000 --- a/prisma/migrations/20231106092655_reading_history/migration.sql +++ /dev/null @@ -1,16 +0,0 @@ --- CreateTable -CREATE TABLE "readinghistory" ( - "id" SERIAL NOT NULL, - "postId" INTEGER NOT NULL, - "userId" INTEGER NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "readinghistory_pkey" PRIMARY KEY ("id") -); - --- AddForeignKey -ALTER TABLE "readinghistory" ADD CONSTRAINT "readinghistory_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "readinghistory" ADD CONSTRAINT "readinghistory_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231108002701_drafts/migration.sql b/prisma/migrations/20231108002701_drafts/migration.sql deleted file mode 100644 index 7492d065..00000000 --- a/prisma/migrations/20231108002701_drafts/migration.sql +++ /dev/null @@ -1,26 +0,0 @@ --- CreateTable -CREATE TABLE "drafts" ( - "id" SERIAL NOT NULL, - "title" TEXT NOT NULL, - "content" TEXT NOT NULL, - "subtitle" VARCHAR(280), - "cover" TEXT, - "views" INTEGER NOT NULL DEFAULT 0, - "postId" INTEGER NOT NULL, - "url" TEXT NOT NULL, - "readingTime" VARCHAR(250), - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - "updated" BOOLEAN NOT NULL DEFAULT false, - - CONSTRAINT "drafts_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "drafts_url_key" ON "drafts"("url"); - --- CreateIndex -CREATE INDEX "drafts_createdAt_idx" ON "drafts"("createdAt"); - --- AddForeignKey -ALTER TABLE "drafts" ADD CONSTRAINT "drafts_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231109163329_add_commend_responses/migration.sql b/prisma/migrations/20231109163329_add_commend_responses/migration.sql deleted file mode 100644 index a7b7dd14..00000000 --- a/prisma/migrations/20231109163329_add_commend_responses/migration.sql +++ /dev/null @@ -1,17 +0,0 @@ --- CreateTable -CREATE TABLE "responses" ( - "id" SERIAL NOT NULL, - "content" TEXT NOT NULL, - "authorId" INTEGER NOT NULL, - "commentId" INTEGER NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "responses_pkey" PRIMARY KEY ("id") -); - --- AddForeignKey -ALTER TABLE "responses" ADD CONSTRAINT "responses_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "responses" ADD CONSTRAINT "responses_commentId_fkey" FOREIGN KEY ("commentId") REFERENCES "comments"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231120085046_update_id_to_string/migration.sql b/prisma/migrations/20231120085046_update_id_to_string/migration.sql deleted file mode 100644 index d75056a7..00000000 --- a/prisma/migrations/20231120085046_update_id_to_string/migration.sql +++ /dev/null @@ -1,199 +0,0 @@ -/* - Warnings: - - - The primary key for the `drafts` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `posts` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The primary key for the `users` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the `responses` table. If the table is not empty, all the data it contains will be lost. - -*/ --- DropForeignKey -ALTER TABLE "accounts" DROP CONSTRAINT "accounts_user_id_fkey"; - --- DropForeignKey -ALTER TABLE "bookmarks" DROP CONSTRAINT "bookmarks_postId_fkey"; - --- DropForeignKey -ALTER TABLE "bookmarks" DROP CONSTRAINT "bookmarks_userId_fkey"; - --- DropForeignKey -ALTER TABLE "commentlikes" DROP CONSTRAINT "commentlikes_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "comments" DROP CONSTRAINT "comments_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "comments" DROP CONSTRAINT "comments_postId_fkey"; - --- DropForeignKey -ALTER TABLE "drafts" DROP CONSTRAINT "drafts_postId_fkey"; - --- DropForeignKey -ALTER TABLE "follows" DROP CONSTRAINT "follows_followerId_fkey"; - --- DropForeignKey -ALTER TABLE "follows" DROP CONSTRAINT "follows_followingId_fkey"; - --- DropForeignKey -ALTER TABLE "likes" DROP CONSTRAINT "likes_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "likes" DROP CONSTRAINT "likes_postId_fkey"; - --- DropForeignKey -ALTER TABLE "notifications" DROP CONSTRAINT "notifications_receiverId_fkey"; - --- DropForeignKey -ALTER TABLE "posts" DROP CONSTRAINT "posts_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "posttags" DROP CONSTRAINT "posttags_postId_fkey"; - --- DropForeignKey -ALTER TABLE "readinghistory" DROP CONSTRAINT "readinghistory_postId_fkey"; - --- DropForeignKey -ALTER TABLE "readinghistory" DROP CONSTRAINT "readinghistory_userId_fkey"; - --- DropForeignKey -ALTER TABLE "responses" DROP CONSTRAINT "responses_authorId_fkey"; - --- DropForeignKey -ALTER TABLE "responses" DROP CONSTRAINT "responses_commentId_fkey"; - --- DropForeignKey -ALTER TABLE "sessions" DROP CONSTRAINT "sessions_user_id_fkey"; - --- DropForeignKey -ALTER TABLE "tagfollows" DROP CONSTRAINT "tagfollows_followerId_fkey"; - --- DropForeignKey -ALTER TABLE "usersettings" DROP CONSTRAINT "usersettings_userId_fkey"; - --- AlterTable -ALTER TABLE "accounts" ALTER COLUMN "user_id" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "bookmarks" ALTER COLUMN "postId" SET DATA TYPE TEXT, -ALTER COLUMN "userId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "commentlikes" ALTER COLUMN "authorId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "comments" ADD COLUMN "parentId" INTEGER, -ALTER COLUMN "postId" SET DATA TYPE TEXT, -ALTER COLUMN "authorId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "drafts" DROP CONSTRAINT "drafts_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "postId" SET DATA TYPE TEXT, -ADD CONSTRAINT "drafts_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "drafts_id_seq"; - --- AlterTable -ALTER TABLE "follows" ALTER COLUMN "followerId" SET DATA TYPE TEXT, -ALTER COLUMN "followingId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "likes" ALTER COLUMN "postId" SET DATA TYPE TEXT, -ALTER COLUMN "authorId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "notifications" ALTER COLUMN "receiverId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "posts" DROP CONSTRAINT "posts_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ALTER COLUMN "authorId" SET DATA TYPE TEXT, -ADD CONSTRAINT "posts_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "posts_id_seq"; - --- AlterTable -ALTER TABLE "posttags" ALTER COLUMN "postId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "readinghistory" ALTER COLUMN "postId" SET DATA TYPE TEXT, -ALTER COLUMN "userId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "sessions" ALTER COLUMN "user_id" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "tagfollows" ALTER COLUMN "followerId" SET DATA TYPE TEXT; - --- AlterTable -ALTER TABLE "users" DROP CONSTRAINT "users_pkey", -ALTER COLUMN "id" DROP DEFAULT, -ALTER COLUMN "id" SET DATA TYPE TEXT, -ADD CONSTRAINT "users_pkey" PRIMARY KEY ("id"); -DROP SEQUENCE "users_id_seq"; - --- AlterTable -ALTER TABLE "usersettings" ALTER COLUMN "userId" SET DATA TYPE TEXT; - --- DropTable -DROP TABLE "responses"; - --- AddForeignKey -ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "posts" ADD CONSTRAINT "posts_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "drafts" ADD CONSTRAINT "drafts_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "comments" ADD CONSTRAINT "comments_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "comments" ADD CONSTRAINT "comments_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "comments" ADD CONSTRAINT "comments_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "comments"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "likes" ADD CONSTRAINT "likes_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "likes" ADD CONSTRAINT "likes_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "commentlikes" ADD CONSTRAINT "commentlikes_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "posttags" ADD CONSTRAINT "posttags_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "follows" ADD CONSTRAINT "follows_followerId_fkey" FOREIGN KEY ("followerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "follows" ADD CONSTRAINT "follows_followingId_fkey" FOREIGN KEY ("followingId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tagfollows" ADD CONSTRAINT "tagfollows_followerId_fkey" FOREIGN KEY ("followerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "notifications" ADD CONSTRAINT "notifications_receiverId_fkey" FOREIGN KEY ("receiverId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "bookmarks" ADD CONSTRAINT "bookmarks_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "bookmarks" ADD CONSTRAINT "bookmarks_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "usersettings" ADD CONSTRAINT "usersettings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "readinghistory" ADD CONSTRAINT "readinghistory_postId_fkey" FOREIGN KEY ("postId") REFERENCES "posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "readinghistory" ADD CONSTRAINT "readinghistory_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231120091110_/migration.sql b/prisma/migrations/20231120091110_/migration.sql deleted file mode 100644 index c57c6371..00000000 --- a/prisma/migrations/20231120091110_/migration.sql +++ /dev/null @@ -1,6 +0,0 @@ --- DropIndex -DROP INDEX "users_username_key"; - --- AlterTable -ALTER TABLE "users" ADD COLUMN "githubId" TEXT, -ALTER COLUMN "username" DROP NOT NULL; diff --git a/prisma/migrations/20231120174236_/migration.sql b/prisma/migrations/20231120174236_/migration.sql deleted file mode 100644 index 6e8b1284..00000000 --- a/prisma/migrations/20231120174236_/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "notifications" ALTER COLUMN "senderId" SET DATA TYPE TEXT; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml deleted file mode 100644 index fbffa92c..00000000 --- a/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "postgresql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 34b31b99..b411b9b0 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -6,150 +6,109 @@ generator client { } datasource db { - provider = "postgresql" - url = env("POSTGRES_URL") - -} - -model Account { - id String @id @default(cuid()) - userId String @map("user_id") - type String - provider String - providerAccountId String @map("provider_account_id") - refresh_token String? @db.Text - access_token String? @db.Text - expires_at Int? - token_type String? - scope String? - id_token String? @db.Text - session_state String? - - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@unique([provider, providerAccountId]) - @@map("accounts") -} - -model Session { - id String @id @default(cuid()) - sessionToken String @unique @map("session_token") - userId String @map("user_id") - expires DateTime - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@map("sessions") -} - -model VerificationToken { - identifier String - token String @unique - expires DateTime - - @@unique([identifier, token]) - @@map("verificationtokens") + provider = "mongodb" + url = env("MONGO_URL") } model User { - id String @id @default(cuid()) - email String? @unique - username String? - name String? - bio String? - password String? - emailVerified DateTime? @map("email_verified") - image String? - accounts Account[] - sessions Session[] - githubprofile String - location String? - verified Boolean @default(false) - falsemember Boolean @default(false) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - githubId String? - settings UserSettings? - notifications Notification[] - posts Post[] - comments Comment[] - likes Like[] - commentlikes CommentLike[] - Followings Follow[] @relation("Follower") - Followers Follow[] @relation("Following") - tagfollower TagFollow[] @relation("TagFollower") - bookmarks Bookmark[] + id String @id @map("_id") @db.ObjectId + email String? @unique + username String? @unique + name String? + bio String? + password String? + emailVerified DateTime? @map("email_verified") + image String? + githubprofile String + location String? + verified Boolean @default(false) + falsemember Boolean @default(false) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + githubId String? + settings UserSettings? + notifications Notification[] + posts Post[] + comments Comment[] + likes Like[] + commentlikes CommentLike[] + Followings Follow[] @relation("Follower") + Followers Follow[] @relation("Following") + tagfollower TagFollow[] @relation("TagFollower") + bookmarks Bookmark[] readinghistory ReadingHistory[] @@map("users") } model Post { - id String @id @default(cuid()) - title String - content String @db.Text - subtitle String? @db.VarChar(280) - cover String? - views Int @default(0) - author User @relation(fields: [authorId], references: [id]) - authorId String - url String @unique - readingTime String? @db.VarChar(250) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - visibility String @default("public") - updated Boolean @default(false) - tags PostTag[] - comments Comment[] - likes Like[] - savedUsers Bookmark[] + id String @id @map("_id") @db.ObjectId + title String + content String? + subtitle String? + cover String? + views Int @default(0) + author User @relation(fields: [authorId], references: [id]) + authorId String @db.ObjectId + url String @unique + readingTime String? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + published Boolean @default(false) + publishedAt DateTime? + updated Boolean @default(false) + tags PostTag[] + comments Comment[] + likes Like[] + savedUsers Bookmark[] readedUsers ReadingHistory[] - drafts DraftPost[] + drafts DraftPost[] + @@index([createdAt]) @@map("posts") } //draft post model to store autosave drafts of posts in editor model DraftPost { - id String @id @default(cuid()) + id String @id @map("_id") @db.ObjectId title String - content String @db.Text - subtitle String? @db.VarChar(280) - cover String? - views Int @default(0) + content String + subtitle String? + cover String? post Post @relation(fields: [postId], references: [id]) - postId String + postId String @db.ObjectId url String @unique - readingTime String? @db.VarChar(250) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - updated Boolean @default(false) @@index([createdAt]) @@map("drafts") } + model Comment { - id Int @id @default(autoincrement()) + id String @id @map("_id") @db.ObjectId content String - author User @relation(fields: [authorId], references: [id]) - authorId String - post Post @relation(fields: [postId], references: [id]) - postId String - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + author User @relation(fields: [authorId], references: [id]) + authorId String @db.ObjectId + post Post @relation(fields: [postId], references: [id]) + postId String @db.ObjectId + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt likes CommentLike[] - replies Comment[] @relation("CommenttoComment") - parentId Int? - parent Comment? @relation("CommenttoComment", fields: [parentId], references: [id]) + replies Comment[] @relation("CommenttoComment") + parentId String? @map("parent_id") @db.ObjectId + parent Comment? @relation("CommenttoComment", fields: [parentId], references: [id], onDelete: NoAction, onUpdate: NoAction) + @@index([createdAt]) @@map("comments") } model Like { - id Int @id @default(autoincrement()) + id String @id @map("_id") @db.ObjectId author User @relation(fields: [authorId], references: [id]) - authorId String + authorId String @db.ObjectId post Post @relation(fields: [postId], references: [id]) - postId String + postId String @db.ObjectId createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -157,11 +116,11 @@ model Like { } model CommentLike { - id Int @id @default(autoincrement()) + id String @id @map("_id") @db.ObjectId author User @relation(fields: [authorId], references: [id]) - authorId String - comment Comment @relation(fields: [commentId], references: [id]) - commentId Int + authorId String @db.ObjectId + comment Comment @relation(fields: [commentId], references: [id]) + commentId String @db.ObjectId createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -169,22 +128,22 @@ model CommentLike { } model Tag { - id Int @id @default(autoincrement()) - name String @unique - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - posts PostTag[] + id String @id @map("_id") @db.ObjectId + name String @unique + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + posts PostTag[] followingtag TagFollow[] @relation("FollowingTag") @@map("tags") } model PostTag { - id Int @id @default(autoincrement()) + id String @id @map("_id") @db.ObjectId post Post @relation(fields: [postId], references: [id]) - postId String + postId String @db.ObjectId tag Tag @relation(fields: [tagId], references: [id]) - tagId Int + tagId String @db.ObjectId createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -192,51 +151,51 @@ model PostTag { } model Follow { - id Int @id @default(autoincrement()) - follower User @relation("Follower", fields: [followerId], references: [id]) - followerId String - following User @relation("Following", fields: [followingId], references: [id]) - followingId String - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @map("_id") @db.ObjectId + follower User @relation("Follower", fields: [followerId], references: [id]) + followerId String @db.ObjectId + following User @relation("Following", fields: [followingId], references: [id]) + followingId String @db.ObjectId + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@map("follows") } model TagFollow { - id Int @id @default(autoincrement()) - follower User @relation("TagFollower", fields: [followerId], references: [id]) - followerId String - tag Tag @relation("FollowingTag", fields: [tagId], references: [id]) - tagId Int - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @map("_id") @db.ObjectId + follower User @relation("TagFollower", fields: [followerId], references: [id]) + followerId String @db.ObjectId + tag Tag @relation("FollowingTag", fields: [tagId], references: [id]) + tagId String @db.ObjectId + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@map("tagfollows") } model Notification { - id Int @id @default(autoincrement()) - content String - read Boolean @default(false) - receiver User @relation(fields: [receiverId], references: [id]) - receiverId String - type String? - url String - senderId String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @map("_id") @db.ObjectId + content String + read Boolean @default(false) + receiver User @relation(fields: [receiverId], references: [id]) + receiverId String @db.ObjectId + type String? + url String + senderId String? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@index([createdAt]) @@map("notifications") } model Bookmark { - id Int @id @default(autoincrement()) + id String @id @map("_id") @db.ObjectId post Post @relation(fields: [postId], references: [id]) - postId String + postId String @db.ObjectId user User @relation(fields: [userId], references: [id]) - userId String + userId String @db.ObjectId createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -244,25 +203,25 @@ model Bookmark { } model UserSettings { - id Int @id @default(autoincrement()) - user User @relation(fields: [userId], references: [id]) - userId String @unique - appearance String @default("system") - language String @default("en") - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @map("_id") @db.ObjectId + user User @relation(fields: [userId], references: [id]) + userId String @unique @db.ObjectId + appearance String @default("system") + language String @default("en") + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@map("usersettings") } model ReadingHistory { - id Int @id @default(autoincrement()) + id String @id @map("_id") @db.ObjectId post Post @relation(fields: [postId], references: [id]) - postId String + postId String @db.ObjectId user User @relation(fields: [userId], references: [id]) - userId String + userId String @db.ObjectId createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@map("readinghistory") -} \ No newline at end of file +}