mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
Adds the per-device APNs identity pair (`apnsToken` + `apnsEnvironment`) to the Device model so the dispatcher can fan a notification out to a user's iPhone via Apple's push gateway. The iOS client decides whether the token belongs to the sandbox or production gateway at registration time — the server never auto-detects, mirroring the W1 stream-2 recommendation. Migration 0037 is strictly additive: both columns nullable, a CHECK constraint pairs them so neither can be set without the other, and a single-column index on `apns_token` backs the dispatcher's per-user lookup plus the cross-user-hijack guard already enforced in `POST /api/devices`. The `NotificationChannel.type` column stays a free-form string — adding "APNS" as the fourth channel-type is a TypeScript-side change in the next commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
1.3 KiB
SQL
31 lines
1.3 KiB
SQL
-- v1.4.23 — APNs send-side scaffolding (Wave 3 / F4)
|
|
--
|
|
-- Adds the per-device APNs identity pair so the dispatcher can fan a
|
|
-- notification out to a user's iPhone via Apple's push gateway. Strictly
|
|
-- additive:
|
|
-- * Both columns nullable — pre-iOS-app rows on disk stay valid.
|
|
-- * `apnsToken` indexed for the dispatcher's per-user lookup +
|
|
-- cross-user-hijack guard in `POST /api/devices`.
|
|
-- * CHECK constraint enforces "if you store an APNs token, you must
|
|
-- also tell us which gateway it belongs to". The iOS client decides
|
|
-- `sandbox` vs `production` at registration time — the server never
|
|
-- auto-detects (per W1 stream-2 recommendation).
|
|
--
|
|
-- The `NotificationChannel.type` column is a free-form String, not a
|
|
-- Postgres enum, so adding the new "APNS" channel-type value is a
|
|
-- TypeScript-side change only — no DDL needed for the channel cascade.
|
|
|
|
ALTER TABLE "devices"
|
|
ADD COLUMN "apns_token" TEXT,
|
|
ADD COLUMN "apns_environment" TEXT;
|
|
|
|
ALTER TABLE "devices"
|
|
ADD CONSTRAINT "devices_apns_environment_required_with_token"
|
|
CHECK (
|
|
("apns_token" IS NULL AND "apns_environment" IS NULL)
|
|
OR
|
|
("apns_token" IS NOT NULL AND "apns_environment" IS NOT NULL)
|
|
);
|
|
|
|
CREATE INDEX "devices_apns_token_idx" ON "devices" ("apns_token");
|