103 lines
2.2 KiB
TypeScript
103 lines
2.2 KiB
TypeScript
import { Database } from "bun:sqlite";
|
|
import { drizzle } from "drizzle-orm/bun-sqlite";
|
|
import { mkdirSync } from "node:fs";
|
|
import { dirname } from "node:path";
|
|
import * as schema from "./schema";
|
|
|
|
const DB_PATH = "./data/cubeadmin.db";
|
|
|
|
// Ensure the data directory exists before opening the database
|
|
mkdirSync(dirname(DB_PATH), { recursive: true });
|
|
|
|
const sqlite = new Database(DB_PATH, { create: true });
|
|
|
|
// Enable WAL mode for better concurrent read performance
|
|
sqlite.exec("PRAGMA journal_mode = WAL;");
|
|
sqlite.exec("PRAGMA foreign_keys = ON;");
|
|
|
|
export const db = drizzle(sqlite, { schema });
|
|
|
|
export type DB = typeof db;
|
|
|
|
// Re-export all schema tables for convenient imports from a single location
|
|
export {
|
|
users,
|
|
sessions,
|
|
accounts,
|
|
verifications,
|
|
invitations,
|
|
mcPlayers,
|
|
playerBans,
|
|
playerChatHistory,
|
|
playerSpawnPoints,
|
|
plugins,
|
|
backups,
|
|
scheduledTasks,
|
|
auditLogs,
|
|
serverSettings,
|
|
} from "./schema";
|
|
|
|
// Re-export Zod schemas
|
|
export {
|
|
insertUserSchema,
|
|
selectUserSchema,
|
|
insertSessionSchema,
|
|
selectSessionSchema,
|
|
insertAccountSchema,
|
|
selectAccountSchema,
|
|
insertVerificationSchema,
|
|
selectVerificationSchema,
|
|
insertInvitationSchema,
|
|
selectInvitationSchema,
|
|
insertMcPlayerSchema,
|
|
selectMcPlayerSchema,
|
|
insertPlayerBanSchema,
|
|
selectPlayerBanSchema,
|
|
insertPlayerChatHistorySchema,
|
|
selectPlayerChatHistorySchema,
|
|
insertPlayerSpawnPointSchema,
|
|
selectPlayerSpawnPointSchema,
|
|
insertPluginSchema,
|
|
selectPluginSchema,
|
|
insertBackupSchema,
|
|
selectBackupSchema,
|
|
insertScheduledTaskSchema,
|
|
selectScheduledTaskSchema,
|
|
insertAuditLogSchema,
|
|
selectAuditLogSchema,
|
|
insertServerSettingsSchema,
|
|
selectServerSettingsSchema,
|
|
} from "./schema";
|
|
|
|
// Re-export inferred types
|
|
export type {
|
|
User,
|
|
NewUser,
|
|
Session,
|
|
NewSession,
|
|
Account,
|
|
NewAccount,
|
|
Verification,
|
|
NewVerification,
|
|
Invitation,
|
|
NewInvitation,
|
|
McPlayer,
|
|
NewMcPlayer,
|
|
PlayerBan,
|
|
NewPlayerBan,
|
|
PlayerChatHistory,
|
|
NewPlayerChatHistory,
|
|
PlayerSpawnPoint,
|
|
NewPlayerSpawnPoint,
|
|
Plugin,
|
|
NewPlugin,
|
|
Backup,
|
|
NewBackup,
|
|
ScheduledTask,
|
|
NewScheduledTask,
|
|
AuditLog,
|
|
NewAuditLog,
|
|
ServerSettings,
|
|
NewServerSettings,
|
|
} from "./schema";
|