Move recipes, chat, settings to shared DB — sync across devices, 1 recipe per meal per day

This commit is contained in:
dadaloop82
2026-03-12 18:06:50 +00:00
parent a7dabbce87
commit f2b090f107
5 changed files with 295 additions and 60 deletions
+42
View File
@@ -76,4 +76,46 @@ function migrateDB(PDO $db): void {
if (!in_array('package_unit', $colNames)) {
$db->exec("ALTER TABLE products ADD COLUMN package_unit TEXT DEFAULT ''");
}
// --- New shared tables ---
// app_settings: key-value store shared across all devices
$tables = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='app_settings'")->fetchAll();
if (empty($tables)) {
$db->exec("
CREATE TABLE app_settings (
key TEXT PRIMARY KEY,
value TEXT NOT NULL DEFAULT '',
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
");
}
// recipes: one per meal per day (last wins)
$tables = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='recipes'")->fetchAll();
if (empty($tables)) {
$db->exec("
CREATE TABLE recipes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date TEXT NOT NULL,
meal TEXT NOT NULL,
recipe_json TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE(date, meal)
);
CREATE INDEX idx_recipes_date ON recipes(date);
");
}
// chat_messages: shared chat history
$tables = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='chat_messages'")->fetchAll();
if (empty($tables)) {
$db->exec("
CREATE TABLE chat_messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
role TEXT NOT NULL,
text TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
");
}
}