-- Permissões RBAC para SPED Fiscal (MySQL)

-- Criar permissões se não existirem
INSERT IGNORE INTO permissions (name) VALUES
  ('fiscal.sped.read'),
  ('fiscal.sped.manage');

-- Vincular permissões ao papel 'admin'
SET @role_id = (SELECT id FROM roles WHERE name = 'admin' LIMIT 1);
SET @perm_read = (SELECT id FROM permissions WHERE name = 'fiscal.sped.read' LIMIT 1);
SET @perm_manage = (SELECT id FROM permissions WHERE name = 'fiscal.sped.manage' LIMIT 1);

INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES
  (@role_id, @perm_read),
  (@role_id, @perm_manage);