This commit is contained in:
MartinBraquet
2025-07-27 21:16:43 +02:00
parent f67ffa2701
commit fde816da8d
2 changed files with 7 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
import {redirect} from "next/navigation";
import Link from "next/link";
import { prisma }from "@/lib/prisma";
import {checkPostTableExists} from "@/lib/db-utils";
import {checkUserTableExists} from "@/lib/db-utils";
// Disable static generation
@@ -10,7 +10,7 @@ export const dynamic = "force-dynamic";
export default async function PostsPage() {
// Check if the post table exists
const tableExists = await checkPostTableExists();
const tableExists = await checkUserTableExists();
// If the post table doesn't exist, redirect to setup page
if (!tableExists) {
@@ -21,7 +21,7 @@ export default async function PostsPage() {
orderBy: {
createdAt: "desc",
},
take: 6,
// take: 20,
// include: {
// author: {
// select: {

View File

@@ -1,15 +1,11 @@
"use server";
import { prisma }from "@/lib/prisma";
import {prisma} from "@/lib/prisma";
/**
* Checks if the Post table exists in the database
* @returns Promise<boolean> - true if the table exists, false otherwise
*/
export async function checkPostTableExists(): Promise<boolean> {
export async function checkUserTableExists(): Promise<boolean> {
try {
// Try to query the post table
await prisma.post.findFirst();
await prisma.user.findFirst();
return true;
} catch {
// If there's an error, the table likely doesn't exist