-- v4.22 -- Enable invoicing for existing cashier employees.
INSERT INTO employee_permissions (employee_id, permission)
SELECT e.id, p.perm
FROM employees e
CROSS JOIN (VALUES
    ('invoicing.view'),
    ('invoicing.create'),
    ('invoicing.cancel')
) AS p(perm)
WHERE e.role = 'cashier'
  AND e.is_active = true
  AND NOT EXISTS (
      SELECT 1 FROM employee_permissions ep
      WHERE ep.employee_id = e.id AND ep.permission = p.perm
  );
