DO $$
BEGIN
    IF to_regclass('user_notifications') IS NULL THEN
        CREATE VIEW user_notifications AS
        SELECT
            "user",
            email_enabled,
            in_app_enabled,
            push_enabled,
            digest_mode,
            dnd_enabled,
            dnd_start_minute,
            dnd_end_minute,
            marketing_enabled,
            security_enabled,
            product_enabled,
            push_subscription_endpoint,
            push_subscription_keys_p256dh,
            push_subscription_keys_auth,
            created_at,
            updated_at
        FROM user_notification;
    END IF;
END $$;
