feat: content store con seed, cache e fallback

This commit is contained in:
2026-07-05 15:43:29 +02:00
parent 6f51aec4c6
commit b22cc40b03
5 changed files with 153 additions and 0 deletions
+4
View File
@@ -1,6 +1,7 @@
import Database from 'better-sqlite3';
import { mkdirSync } from 'node:fs';
import { dirname } from 'node:path';
import { contentSeed } from '../data/content-seed';
const SCHEMA = `
CREATE TABLE IF NOT EXISTS posts (
@@ -49,6 +50,9 @@ export function createDb(path?: string): Database.Database {
if (!userCols.some((c) => c.name === 'role')) {
db.exec(`ALTER TABLE users ADD COLUMN role TEXT NOT NULL DEFAULT 'admin'`);
}
const ins = db.prepare('INSERT OR IGNORE INTO content_blocks (tag, type, value) VALUES (?, ?, ?)');
const syncTx = db.transaction(() => { for (const e of contentSeed) ins.run(e.tag, e.type, e.value); });
syncTx();
return db;
}