-- More than one profile per user (Marcus, 2026-11-26: operador/revisor, -- gestor/operador/revisor): what a user may do is the sum of their profiles. -- `role` stays the main one, shown first and kept for superadmin; `roles` -- holds every profile, the main one included. ALTER TABLE dtf_local.operators ADD COLUMN IF NOT EXISTS roles text[] NOT NULL DEFAULT '{}'; UPDATE dtf_local.operators SET roles=ARRAY[role] WHERE cardinality(roles)=0; DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='operators_roles' AND conrelid='dtf_local.operators'::regclass) THEN ALTER TABLE dtf_local.operators ADD CONSTRAINT operators_roles CHECK (roles <@ ARRAY['superadmin','admin','gestao','designer','operador','revisor','vendedor','financeiro','expedicao']::text[]); END IF; END $$;