-- Permissões RBAC para módulo Serviços (MySQL)

-- Criar permissões se não existirem
INSERT IGNORE INTO permissions (name) VALUES
  ('servicos.read'),
  ('servicos.create'),
  ('servicos.update'),
  ('servicos.delete');

-- 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 = 'servicos.read' LIMIT 1);
SET @perm_create = (SELECT id FROM permissions WHERE name = 'servicos.create' LIMIT 1);
SET @perm_update = (SELECT id FROM permissions WHERE name = 'servicos.update' LIMIT 1);
SET @perm_delete = (SELECT id FROM permissions WHERE name = 'servicos.delete' LIMIT 1);

INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES
  (@role_id, @perm_read),
  (@role_id, @perm_create),
  (@role_id, @perm_update),
  (@role_id, @perm_delete);