-- Migration: Add push_subscriptions table for Web Push notifications
-- Run this on existing databases to enable push notification support
-- Date: 2026-02-05

-- Push notification subscriptions (for Web Push API)
CREATE TABLE IF NOT EXISTS push_subscriptions (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    endpoint TEXT NOT NULL,
    p256dh TEXT NOT NULL,
    auth TEXT NOT NULL,
    device_info TEXT,
    created_at TIMESTAMP DEFAULT NOW(),
    UNIQUE(user_id, endpoint)
);

-- Index for faster lookups by user_id
CREATE INDEX IF NOT EXISTS idx_push_subscriptions_user ON push_subscriptions(user_id);

-- Success message
SELECT 'Push subscriptions table created successfully!' as status;
