-- +goose Up
-- +goose StatementBegin

INSERT INTO permissions (code, name, resource, action) VALUES
('notification:view', '查看通知', 'notification', 'view')
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  resource = VALUES(resource),
  action = VALUES(action);

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id
FROM roles r
JOIN permissions p ON p.code = 'notification:view'
WHERE r.code IN ('super_admin', 'cs', 'ops');

-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin

DELETE rp FROM role_permissions rp
JOIN permissions p ON p.id = rp.permission_id
WHERE p.code = 'notification:view';

DELETE FROM permissions WHERE code = 'notification:view';

-- +goose StatementEnd
