34 lines
1004 B
TypeScript
34 lines
1004 B
TypeScript
import { DatabaseSync } from 'node:sqlite';
|
|
import path from 'node:path';
|
|
import fs from 'node:fs';
|
|
|
|
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
|
const DB_PATH = path.join(DATA_DIR, 'waas.db');
|
|
|
|
export function resetDatabaseToBlankSlate(): void {
|
|
const db = new DatabaseSync(DB_PATH);
|
|
|
|
// Lösche bestehende Seiten & Sektionen
|
|
db.exec('DELETE FROM page_sections');
|
|
db.exec('DELETE FROM pages');
|
|
|
|
const now = new Date().toISOString();
|
|
|
|
// Leere Startseite anlegen (ohne vordefinierte Sektionen/Inhalte)
|
|
db.prepare('INSERT INTO pages (id, slug, title, status, homepage_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)').run(
|
|
'page_home',
|
|
'/',
|
|
'Startseite',
|
|
'published',
|
|
'page_home',
|
|
now,
|
|
now
|
|
);
|
|
|
|
console.log('[WaaS DB] Datenbank auf leeren Stand (Blank Slate) zurückgesetzt.');
|
|
}
|
|
|
|
if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('resetDb.ts')) {
|
|
resetDatabaseToBlankSlate();
|
|
}
|