mitai-jinkendo/backend/migrations/069_food_catalog_visibility.sql
Lars 8b1e1da5d8
All checks were successful
Deploy Development / deploy (push) Successful in 1m5s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 24s
feat: Eigene und zentrale Lebensmittel bearbeiten, mit Sichtbarkeit im Mapping
Nutzer können persönliche Foods anlegen und ändern; der Admin legt zentrale Einträge für alle an. Suche und Namens-Mapping berücksichtigen persönlich, zentral und BLS.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-14 12:47:12 +02:00

19 lines
647 B
SQL

-- Visibility invariant: personal foods have an owner; BLS and central admin foods do not.
UPDATE food_catalog
SET owner_profile_id = NULL
WHERE catalog_kind IN ('official_bls', 'manual_admin')
AND owner_profile_id IS NOT NULL;
UPDATE food_catalog
SET is_active = false
WHERE catalog_kind = 'manual_user'
AND owner_profile_id IS NULL;
ALTER TABLE food_catalog DROP CONSTRAINT IF EXISTS chk_food_catalog_owner;
ALTER TABLE food_catalog ADD CONSTRAINT chk_food_catalog_owner CHECK (
(catalog_kind = 'manual_user' AND owner_profile_id IS NOT NULL)
OR (catalog_kind IN ('official_bls', 'manual_admin') AND owner_profile_id IS NULL)
);