START TRANSACTION;

INSERT IGNORE INTO permissions (code, name, module, created_at) VALUES
('pos.access', 'Akses POS', 'pos', NOW());

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT DISTINCT rp.role_id, target.id
FROM role_permissions rp
JOIN permissions source ON source.id = rp.permission_id
JOIN permissions target ON target.code = 'pos.access'
WHERE source.code IN ('pos.view', 'pos.add', 'pos.claim.offer', 'pos.claim.override');

COMMIT;
