Files
honeyDueAPI/migrations/013_business_constraints.up.sql
treyt e26116e2cf Add webhook logging, pagination, middleware, migrations, and prod hardening
- Webhook event logging repo and subscription webhook idempotency
- Pagination helper (echohelpers) with cursor/offset support
- Request ID and structured logging middleware
- Push client improvements (FCM HTTP v1, better error handling)
- Task model version column, business constraint migrations, targeted indexes
- Expanded categorization chain tests
- Email service and config hardening
- CI workflow updates, .gitignore additions, .env.example updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 21:32:09 -06:00

32 lines
1.1 KiB
SQL

-- Prevent task from being both cancelled and archived simultaneously
ALTER TABLE task_task ADD CONSTRAINT chk_task_not_cancelled_and_archived
CHECK (NOT (is_cancelled = true AND is_archived = true));
-- Subscription tier must be valid
ALTER TABLE subscriptions_usersubscription ADD CONSTRAINT chk_subscription_tier
CHECK (tier IN ('free', 'pro'));
-- Notification: sent_at must be set if sent is true
ALTER TABLE notifications_notification ADD CONSTRAINT chk_notification_sent_consistency
CHECK ((sent = false) OR (sent = true AND sent_at IS NOT NULL));
-- One subscription per user
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'uq_subscription_user'
) THEN
ALTER TABLE subscriptions_usersubscription ADD CONSTRAINT uq_subscription_user UNIQUE (user_id);
END IF;
END $$;
-- One notification preference per user
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'uq_notif_pref_user'
) THEN
ALTER TABLE notifications_notificationpreference ADD CONSTRAINT uq_notif_pref_user UNIQUE (user_id);
END IF;
END $$;