Erstes lauffähiges Grundgerüst: Monorepo, Fastify-API, React-Startseite, Docker

This commit is contained in:
2026-07-19 01:14:29 +02:00
parent 657496fe49
commit 7b8723729b
39 changed files with 4388 additions and 15 deletions

View File

@@ -0,0 +1,70 @@
import { existsSync, mkdirSync } from "node:fs";
import { dirname } from "node:path";
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "./schema.js";
const databasePath = process.env.DATABASE_PATH ?? "./data/launchpad.db";
// Stellt sicher, dass das Verzeichnis für die SQLite-Datei existiert
// (relevant im Docker-Volume /data).
const dir = dirname(databasePath);
if (dir !== "." && !existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
const sqlite = new Database(databasePath);
sqlite.pragma("journal_mode = WAL");
sqlite.pragma("foreign_keys = ON");
export const db = drizzle(sqlite, { schema });
/**
* Legt die Tabellen an, falls sie noch nicht existieren.
* Für den ersten Commit reicht ein einfaches "CREATE TABLE IF NOT EXISTS",
* spätere Commits ersetzen dies durch echte Drizzle-Migrationen (drizzle-kit).
*/
export function ensureSchema(): void {
sqlite.exec(`
CREATE TABLE IF NOT EXISTS devices (
id TEXT PRIMARY KEY,
hostname TEXT NOT NULL,
ip TEXT NOT NULL,
mac TEXT,
manufacturer TEXT,
model TEXT,
online INTEGER NOT NULL DEFAULT 0,
source TEXT NOT NULL,
last_scan TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS services (
id TEXT PRIMARY KEY,
device_id TEXT NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
display_name TEXT NOT NULL,
category TEXT,
favorite INTEGER NOT NULL DEFAULT 0,
"order" REAL NOT NULL DEFAULT 0,
alias TEXT NOT NULL DEFAULT '[]',
icon TEXT,
hostname TEXT NOT NULL,
url TEXT NOT NULL,
https INTEGER NOT NULL DEFAULT 0,
port INTEGER NOT NULL,
favicon TEXT,
description TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS categories (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
"order" REAL NOT NULL DEFAULT 0,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
`);
}