-- The Communication module (Mail, Meetings, WhatsApp) was never added to any subscription
-- plan's `modules` seed data, so ModuleAccessFilter rejects every /api/communication/** and
-- /api/mail-oauth/** request with 403 MODULE_ACCESS_DENIED for every tenant, regardless of
-- role — TENANT_ADMIN included. Same class of gap as fix_enterprise_plan_missing_web_module.sql.
-- Adds "Communication" to the Professional and Enterprise plans only (Basic stays as-is).
-- Idempotent (JSON_CONTAINS-guarded), additive only.
-- Deploy: mysql -u root -p db_abos_v0.1 < db/fix_communication_module_missing_from_plans.sql

USE db_abos_v0.1;

UPDATE dim_subscription_plans
SET modules = JSON_ARRAY_APPEND(modules, '$', 'Communication')
WHERE name IN ('Professional', 'Enterprise')
  AND NOT JSON_CONTAINS(modules, '"Communication"');
