-- ==================================================================== -- 0062_push_platform — Push-Abos plattformfähig machen (Web + Expo/nativ) -- ==================================================================== -- Migration 0060 legte push_subscriptions für Web-Push (VAPID) an: -- endpoint/p256dh/auth sind Browser-Push-Spezifika und NOT NULL. Die native -- App nutzt stattdessen den Expo-Push-Service (ein Token, Expo relayed an -- APNs/FCM) — dort gibt es kein p256dh/auth. Wir erweitern die Tabelle um -- eine platform-Spalte und einen expo_push_token, und lockern die Web-only- -- Spalten auf NULLable, damit Expo-Abos ohne sie gespeichert werden können. -- -- Bestandsdaten: alle vorhandenen Zeilen sind Web-Abos → platform='web' -- (Default deckt das ab). Der Versand-Fork in lib/push.ts wählt anhand von -- platform den richtigen Kanal. alter table public.push_subscriptions add column if not exists platform text not null default 'web', add column if not exists expo_push_token text; -- Web-only-Spalten für Expo-Abos optional machen. alter table public.push_subscriptions alter column endpoint drop not null; alter table public.push_subscriptions alter column p256dh drop not null; alter table public.push_subscriptions alter column auth drop not null; -- Ein Expo-Push-Token darf nur einmal existieren (ein Gerät = ein Abo), -- analog zum unique endpoint bei Web. Partieller Index, damit mehrere -- Web-Zeilen mit NULL-Token nicht kollidieren. create unique index if not exists push_subscriptions_expo_token_key on public.push_subscriptions (expo_push_token) where expo_push_token is not null; -- Integrität: je nach platform müssen die passenden Felder gesetzt sein. alter table public.push_subscriptions drop constraint if exists push_subscriptions_platform_fields; alter table public.push_subscriptions add constraint push_subscriptions_platform_fields check ( (platform = 'web' and endpoint is not null and p256dh is not null and auth is not null) or (platform = 'expo' and expo_push_token is not null) );