ALTER TABLE mesh_route_intents
    DROP CONSTRAINT IF EXISTS mesh_route_intents_service_class_check;

ALTER TABLE mesh_route_intents
    ADD CONSTRAINT mesh_route_intents_service_class_check
        CHECK (service_class IN ('input', 'control', 'synthetic', 'render', 'clipboard', 'file_transfer', 'vpn_packets', 'telemetry'));

ALTER TABLE mesh_qos_policies
    DROP CONSTRAINT IF EXISTS mesh_qos_policies_service_class_check;

ALTER TABLE mesh_qos_policies
    ADD CONSTRAINT mesh_qos_policies_service_class_check
        CHECK (service_class IN ('input', 'control', 'synthetic', 'render', 'clipboard', 'file_transfer', 'vpn_packets', 'telemetry'));

INSERT INTO mesh_qos_policies (
    cluster_id, service_class, priority, reliability_mode, drop_policy, bandwidth_policy, metadata
)
SELECT c.id, 'synthetic', 30, 'reliable', 'never', '{}'::jsonb,
       '{"default":true,"control_plane_only":true}'::jsonb
FROM clusters c
ON CONFLICT (cluster_id, service_class) DO NOTHING;
