Rebuild atomcms-next foundation on Prisma (align to habbo-next reference)

Replace the superseded Drizzle monorepo scaffold with a single-app Prisma 7
data layer, mirroring the proven habbo-next approach to the shared Arcturus
emulator DB (introspect/conform only, idempotent SQL migrations via a custom
runner; never migrate-diff).

- prisma/schema.prisma: User, UsersCurrency (composite PK), Ban, WebsiteSetting
  mapped to AtomCMS's default.sql columns; client generated to src/generated/prisma
- src/lib/prisma.ts: PrismaMariaDb adapter singleton; src/env.ts zod env
- src/lib/services: siteSettings (cached setting() equivalent) + CurrencyType enum
- prisma/migrations + scripts/apply-migrations.ts: idempotent CMS-table runner

Verified: prisma generate OK, tsc --noEmit exit 0, vitest 6/6 pass.
This commit is contained in:
Simo committed 2026-06-27 15:26:40 +02:00
1 parent 7bd4f2b28e
commit b5bc7f6daf
44 files changed
+1279 -511

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import { prisma } from "@/lib/prisma";
/**
* DB-driven CMS config, mirroring AtomCMS's `setting()` / habbo-next's
* `siteSettings`. Loads the whole website_settings table into a key→value map,
* cached in-process. Booleans are stored as the strings '1' / '0'.
*/
class SiteSettings {
private cache: Map<string, string> | null = null;
private async load(): Promise<Map<string, string>> {
if (this.cache === null) {
const rows = await prisma.websiteSetting.findMany({
select: { key: true, value: true },
});
this.cache = new Map(rows.map((r) => [r.key, r.value]));
}
return this.cache;
}
async get(key: string, fallback: string | null = null): Promise<string | null> {
const map = await this.load();
return map.has(key) ? (map.get(key) as string) : fallback;
}
async getBool(key: string, fallback = false): Promise<boolean> {
const map = await this.load();
if (!map.has(key)) return fallback;
const v = (map.get(key) as string).toLowerCase();
return v === "1" || v === "true";
}
/** Invalidate the in-process cache after a settings write. */
reload(): void {
this.cache = null;
}
}
export const siteSettings = new SiteSettings();