--liquibase formatted sql -- PANELS · iam · permisos de facturas --changeset panel:iam-007a-invoices endDelimiter:; splitStatements:true INSERT INTO iam.permissions (code, label, module, verb, perm_group) VALUES ('invoices.view', 'Ver facturas', 'invoices', 'view', NULL), ('invoices.create', 'Importar facturas', 'invoices', 'create', NULL), ('invoices.update', 'Clasificar facturas', 'invoices', 'update', NULL) ON CONFLICT (code) DO UPDATE SET label = EXCLUDED.label, module = EXCLUDED.module, verb = EXCLUDED.verb, perm_group = EXCLUDED.perm_group; INSERT INTO iam._legacy_perm_map (legacy_code, v2_code) VALUES ('manage_expenses', 'invoices.view'), ('manage_expenses', 'invoices.create'), ('manage_expenses', 'invoices.update'), ('view_expenses', 'invoices.view') ON CONFLICT (legacy_code, v2_code) DO NOTHING; INSERT INTO iam.role_permissions (role_id, permission_code) SELECT sr.id, p.code FROM iam.roles sr JOIN iam.permissions p ON p.code IN ('invoices.view', 'invoices.create', 'invoices.update') WHERE sr.code = 'tenant_admin' AND sr.is_system AND sr.tenant_id IS NULL ON CONFLICT DO NOTHING;