refactor: clear sample pages and sections to provide a clean slate for custom editing
This commit is contained in:
33
src/db/resetDb.ts
Normal file
33
src/db/resetDb.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user