Files
fabrikanabytok/apps/fabrikanabytok/app/(platform)/admin/migrations/page.tsx
2025-11-28 20:47:59 +01:00

115 lines
4.2 KiB
TypeScript

import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Database, Play, CheckCircle, AlertTriangle } from "lucide-react"
import { runAllMigrations } from "@/lib/db/migrations"
import { redirect } from "next/navigation"
import { auth } from "@/lib/auth/auth"
export default async function MigrationsPage() {
const session = await auth()
if (!session?.user || session.user.role !== "superadmin") {
redirect("/admin")
}
async function handleRunMigrations() {
"use server"
const results = await runAllMigrations()
return results
}
return (
<div className="space-y-6">
<div>
<h2 className="text-3xl font-bold">Database Migrations</h2>
<p className="text-muted-foreground mt-1">
Run migrations to ensure all documents have custom UUID fields
</p>
</div>
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Database className="w-5 h-5" />
Security & ID Migration
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="rounded-lg bg-amber-50 border border-amber-200 p-4">
<div className="flex items-start gap-2">
<AlertTriangle className="w-5 h-5 text-amber-600 mt-0.5" />
<div>
<h4 className="font-semibold text-amber-900 mb-1">Important</h4>
<p className="text-sm text-amber-700">
This migration adds custom UUID fields (id) to all documents.
This replaces MongoDB ObjectId (_id) for improved security.
</p>
</div>
</div>
</div>
<div className="space-y-3">
<h4 className="font-medium">Migrations to Run:</h4>
<div className="space-y-2">
<div className="flex items-center justify-between p-3 border rounded-lg">
<div>
<div className="font-medium">Products Migration</div>
<div className="text-xs text-muted-foreground">
Add custom id field to all products
</div>
</div>
<Badge variant="secondary">Automatic</Badge>
</div>
<div className="flex items-center justify-between p-3 border rounded-lg">
<div>
<div className="font-medium">Categories Migration</div>
<div className="text-xs text-muted-foreground">
Add custom id field to all categories
</div>
</div>
<Badge variant="secondary">Automatic</Badge>
</div>
<div className="flex items-center justify-between p-3 border rounded-lg">
<div>
<div className="font-medium">Designs Enhancement</div>
<div className="text-xs text-muted-foreground">
Add enhanced fields (layers, snapSettings, renderSettings)
</div>
</div>
<Badge variant="secondary">Automatic</Badge>
</div>
<div className="flex items-center justify-between p-3 border rounded-lg">
<div>
<div className="font-medium">Placed Objects Enhancement</div>
<div className="text-xs text-muted-foreground">
Add hierarchical and material properties
</div>
</div>
<Badge variant="secondary">Automatic</Badge>
</div>
</div>
</div>
<form action={handleRunMigrations}>
<Button type="submit" className="w-full gap-2" size="lg">
<Play className="w-4 h-4" />
Run All Migrations
</Button>
</form>
<div className="text-xs text-muted-foreground">
Note: Running migrations is safe and can be run multiple times.
Only documents missing custom IDs will be updated.
</div>
</CardContent>
</Card>
</div>
)
}