-- ============================================================
-- Schema Update v3
-- Run this AFTER schema.sql and schema_update_v2.sql.
-- Adds per-user permission grants, so superadmin/admin can give any
-- individual user extra abilities regardless of their role
-- (e.g. let a "supervisor" issue stock, or let a "staff" manage suppliers).
-- ============================================================

CREATE TABLE IF NOT EXISTS user_permissions (
  user_id INT NOT NULL,
  permission_code VARCHAR(60) NOT NULL,
  granted_by INT NULL,
  granted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (user_id, permission_code),
  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB;
