Reconcile website_* schema to the live AtomCMS DB (amx_test)

Introspected the live DB and fixed real drift between the hand-modeled
schema and the actual columns:
- Added missing @map("snake_case") on camelCase fields that silently
  failed at query time: website_teams (rank_name/hidden_rank/...),
  website_paypal_transactions/user_guestbooks/help_center_tickets(+replies)/
  used_shop_vouchers/maintenance_tasks (user_id), website_rare_values
  (currency_type).
- website_permissions was modeled as key/value/comment but is actually
  permission/min_rank/description — fixed the model + the admin page/action.
- website_shop_articles.icon -> icon_url (+ added category_id, is_giftable);
  updated the shop page + admin shop CRUD.
- website_shop_categories: dropped non-existent slug/timestamps, added the
  real description/order columns; updated the shop page.
- website_shop_article_features.features(Json) -> content(Text).

Verified against amx_test: all website_* query errors gone; home renders
the real hotel_name ("Habbo"), rankings shows real users, /staff + /shop
200. tsc 0, vitest 49/49, next build 0. Remaining missing tables
(radio_*/game_*/staff_activities/alert_logs/article_comments+reactions)
don't exist in this DB and degrade gracefully via try/catch.
This commit is contained in:
Simo committed 2026-06-28 16:35:27 +02:00
1 parent 4eccd146ba
commit b97a88c561
6 files changed
+92 -93

No files matched your search

+26 -33
View File
@@ -5,36 +5,34 @@ import { requireStaff } from "@/lib/admin/guard";
import { prisma } from "@/lib/prisma";
import { logStaffActivity } from "@/lib/services/staff-activity";
// website_permissions (model WebsitePermissions) is the CMS-owned rank-permission
// mapping AtomCMS exposes in admin: a key/value(/comment) row per permission.
// Editable columns on the table are exactly: key (unique), value, comment.
// id is BigInt and created_at/updated_at are managed here — no other columns
// exist, so there are no extra staff flags to toggle.
// website_permissions (model WebsitePermissions) is the CMS-owned permission ->
// minimum-rank mapping. Editable columns are exactly: permission (unique name),
// min_rank (lowest rank that may use it), description. id is BigInt and
// created_at/updated_at are managed here.
function parseMinRank(formData: FormData): number {
const n = Number(String(formData.get("minRank") ?? "").trim());
return Number.isInteger(n) && n >= 0 ? n : 1;
}
export async function createPermission(formData: FormData): Promise<void> {
const staff = await requireStaff();
const key = String(formData.get("key") ?? "").trim().slice(0, 255);
const value = String(formData.get("value") ?? "").trim().slice(0, 255);
const comment = String(formData.get("comment") ?? "").trim().slice(0, 255);
if (!key) return;
const permission = String(formData.get("permission") ?? "").trim().slice(0, 255);
const minRank = parseMinRank(formData);
const description = String(formData.get("description") ?? "").trim() || null;
if (!permission) return;
const now = new Date();
try {
await prisma.websitePermissions.upsert({
where: { key },
update: { value: value || null, comment: comment || null, updatedAt: now },
create: {
key,
value: value || null,
comment: comment || null,
createdAt: now,
updatedAt: now,
},
where: { permission },
update: { minRank, description, updatedAt: now },
create: { permission, minRank, description, createdAt: now, updatedAt: now },
});
await logStaffActivity({
staffId: staff.id,
action: "permission_create",
description: `Saved permission "${key}" = "${value}"`,
description: `Saved permission "${permission}" (min rank ${minRank})`,
targetType: "permission",
});
} catch {
@@ -48,29 +46,24 @@ export async function updatePermission(formData: FormData): Promise<void> {
const raw = String(formData.get("id") ?? "");
if (!raw) return;
const id = BigInt(raw);
const key = String(formData.get("key") ?? "").trim().slice(0, 255);
const value = String(formData.get("value") ?? "").trim().slice(0, 255);
const comment = String(formData.get("comment") ?? "").trim().slice(0, 255);
if (!key) return;
const permission = String(formData.get("permission") ?? "").trim().slice(0, 255);
const minRank = parseMinRank(formData);
const description = String(formData.get("description") ?? "").trim() || null;
if (!permission) return;
try {
await prisma.websitePermissions.update({
where: { id },
data: {
key,
value: value || null,
comment: comment || null,
updatedAt: new Date(),
},
data: { permission, minRank, description, updatedAt: new Date() },
});
await logStaffActivity({
staffId: staff.id,
action: "permission_update",
description: `Updated permission #${raw} ("${key}" = "${value}")`,
description: `Updated permission #${raw} ("${permission}" min rank ${minRank})`,
targetType: "permission",
});
} catch {
// ignore (e.g. duplicate key) — page re-renders current state
// ignore (e.g. duplicate) — page re-renders current state
}
revalidatePath("/admin/permissions");
}
@@ -83,12 +76,12 @@ export async function deletePermission(formData: FormData): Promise<void> {
try {
const deleted = await prisma.websitePermissions.delete({
where: { id: BigInt(raw) },
select: { key: true },
select: { permission: true },
});
await logStaffActivity({
staffId: staff.id,
action: "permission_delete",
description: `Deleted permission #${raw} ("${deleted.key}")`,
description: `Deleted permission #${raw} ("${deleted.permission}")`,
targetType: "permission",
});
} catch {
+2 -2
View File
@@ -37,7 +37,7 @@ export async function createShopArticle(formData: FormData): Promise<void> {
data: {
name,
info: String(formData.get("info") ?? "").trim().slice(0, 255),
icon: String(formData.get("icon") ?? "").trim().slice(0, 255),
iconUrl: String(formData.get("icon") ?? "").trim().slice(0, 255),
color: String(formData.get("color") ?? "").trim().slice(0, 255),
costs: reqUInt(formData, "costs"),
giveRank: optUInt(formData, "giveRank"),
@@ -86,7 +86,7 @@ export async function updateShopArticle(formData: FormData): Promise<void> {
data: {
name,
info: String(formData.get("info") ?? "").trim().slice(0, 255),
icon: String(formData.get("icon") ?? "").trim().slice(0, 255),
iconUrl: String(formData.get("icon") ?? "").trim().slice(0, 255),
color: String(formData.get("color") ?? "").trim().slice(0, 255),
costs: reqUInt(formData, "costs"),
giveRank: optUInt(formData, "giveRank"),