23 lines
971 B
SQL
23 lines
971 B
SQL
-- Add web push notification fields to users table
|
|
ALTER TABLE users
|
|
ADD COLUMN push_tokens JSONB DEFAULT NULL,
|
|
ADD COLUMN push_notifications_enabled BOOLEAN DEFAULT true,
|
|
ADD COLUMN last_push_notification_at TIMESTAMPTZ DEFAULT NULL;
|
|
|
|
-- Add indexes for better performance
|
|
CREATE INDEX IF NOT EXISTS idx_users_push_notifications_enabled ON users (push_notifications_enabled)
|
|
WHERE
|
|
push_notifications_enabled = true
|
|
AND deleted_at IS NULL;
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_users_push_tokens ON users USING GIN (push_tokens)
|
|
WHERE
|
|
push_tokens IS NOT NULL
|
|
AND deleted_at IS NULL;
|
|
|
|
-- Add comment for documentation
|
|
COMMENT ON COLUMN users.push_tokens IS 'JSON array of web push subscription objects containing endpoint and keys';
|
|
|
|
COMMENT ON COLUMN users.push_notifications_enabled IS 'Whether web push notifications are enabled for this user';
|
|
|
|
COMMENT ON COLUMN users.last_push_notification_at IS 'Timestamp of the last push notification sent to this user'; |