-- Item Code as its own permission module

INSERT INTO permissions (code, name, module) VALUES
('item_code.view', 'View Item Code', 'item_code'),
('item_code.add', 'Add Item Code', 'item_code'),
('item_code.edit', 'Edit Item Code', 'item_code'),
('item_code.delete', 'Delete Item Code', 'item_code')
ON DUPLICATE KEY UPDATE name = VALUES(name), module = VALUES(module);

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id
FROM roles r
CROSS JOIN permissions p
WHERE r.code = 'ADMIN'
  AND r.is_system = 1
  AND p.module = 'item_code';
