75 lines
2.2 KiB
JavaScript
75 lines
2.2 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const Database = require('better-sqlite3');
|
|
const bcrypt = require('bcryptjs');
|
|
|
|
const dbPath = path.join(__dirname, 'data.db');
|
|
const db = new Database(dbPath);
|
|
|
|
db.pragma('journal_mode = WAL');
|
|
|
|
// Tabellen anlegen
|
|
db.exec(`
|
|
CREATE TABLE IF NOT EXISTS config (
|
|
key TEXT PRIMARY KEY,
|
|
value TEXT
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS product_groups (
|
|
id TEXT PRIMARY KEY,
|
|
name TEXT,
|
|
sort_order INTEGER DEFAULT 0
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS products (
|
|
id TEXT PRIMARY KEY,
|
|
text1 TEXT NOT NULL,
|
|
text2 TEXT,
|
|
group_id TEXT,
|
|
preis1 REAL DEFAULT 0,
|
|
unit TEXT,
|
|
active INTEGER DEFAULT 1,
|
|
sort_order INTEGER DEFAULT 0,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS sync_logs (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
status TEXT,
|
|
message TEXT,
|
|
items_count INTEGER DEFAULT 0
|
|
);
|
|
`);
|
|
|
|
// Standard Admin Initialisieren
|
|
const adminUser = db.prepare('SELECT value FROM config WHERE key = ?').get('admin_user');
|
|
if (!adminUser) {
|
|
const hash = bcrypt.hashSync('Kathi2022!', 10);
|
|
db.prepare('INSERT INTO config (key, value) VALUES (?, ?)').run('admin_user', 'admin');
|
|
db.prepare('INSERT INTO config (key, value) VALUES (?, ?)').run('admin_password_hash', hash);
|
|
db.prepare('INSERT INTO config (key, value) VALUES (?, ?)').run('jwt_secret', 'secret_' + Math.random().toString(36).substring(2));
|
|
}
|
|
|
|
// Standard Theme & Texte initialisieren
|
|
const initConfig = (k, v) => {
|
|
const existing = db.prepare('SELECT value FROM config WHERE key = ?').get(k);
|
|
if (!existing) {
|
|
db.prepare('INSERT INTO config (key, value) VALUES (?, ?)').run(k, v);
|
|
}
|
|
};
|
|
|
|
initConfig('site_title', 'GETRÄNKEKARTE');
|
|
initConfig('site_subtitle', 'Frisch zubereitete Drinks, Spezialitäten & Erfrischungen');
|
|
initConfig('site_badge', '✦ EXKLUSIVE AUSWAHL ✦');
|
|
initConfig('site_footer', '© Bar & Lounge • Live POS Sync');
|
|
|
|
initConfig('theme_bg', '#090b10');
|
|
initConfig('theme_card_bg', 'rgba(22, 27, 34, 0.75)');
|
|
initConfig('theme_primary', '#f59e0b');
|
|
initConfig('theme_accent', '#ec4899');
|
|
initConfig('theme_text', '#f8fafc');
|
|
initConfig('theme_text_muted', '#94a3b8');
|
|
|
|
module.exports = db;
|