diff --git a/api/database.php b/api/database.php index df8a8fb..601e856 100644 --- a/api/database.php +++ b/api/database.php @@ -515,6 +515,28 @@ if (empty($recipeTagsTables)) { ('brunch', 'Brunch', '🥂', 23) "); } +// Custom quantity units (v2.4) — unités personnalisées (ex: kg, L) avec facteur de conversion vers pz/g/ml, gérables depuis Config +$customUnitsTables = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='custom_units'")->fetchAll(); +if (empty($customUnitsTables)) { + $db->exec(" + CREATE TABLE custom_units ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + key TEXT UNIQUE NOT NULL, + label TEXT NOT NULL, + icon TEXT DEFAULT '📏', + base_unit TEXT NOT NULL DEFAULT 'g', + factor REAL NOT NULL DEFAULT 1, + sort_order INTEGER DEFAULT 0 + ); + "); +} +// Add display_unit_key column to products if missing — unité personnalisée a afficher pour ce produit +$prodColsUnits = array_column($db->query("PRAGMA table_info(products)")->fetchAll(), 'name'); +if (!in_array('display_unit_key', $prodColsUnits)) { + try { $db->exec("ALTER TABLE products ADD COLUMN display_unit_key TEXT DEFAULT NULL"); } + catch (PDOException $e) { if (strpos($e->getMessage(), 'duplicate column') === false) throw $e; } +} + // Internal shopping list table (v1.8.0) — used when SHOPPING_MODE=internal // Internal shopping list table (v1.8.0) — used when SHOPPING_MODE=internal $shopTables = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='shopping_list'")->fetchAll();