-- Migration: Add missing granular permission columns to users table
-- These are referenced in settings/users.php but missing from the DB schema
-- MySQL 5.7 compatible

ALTER TABLE `users`
  ADD COLUMN `perm_costings`   TINYINT(1) NOT NULL DEFAULT 0,
  ADD COLUMN `perm_assign`     TINYINT(1) NOT NULL DEFAULT 0,
  ADD COLUMN `perm_customers`  TINYINT(1) NOT NULL DEFAULT 0,
  ADD COLUMN `perm_invoices`   TINYINT(1) NOT NULL DEFAULT 0,
  ADD COLUMN `perm_financials` TINYINT(1) NOT NULL DEFAULT 0,
  ADD COLUMN `perm_photos`     TINYINT(1) NOT NULL DEFAULT 0;

-- Give admin/manager full access to new perms
UPDATE `users` SET
  perm_costings=1, perm_assign=1, perm_customers=1,
  perm_invoices=1, perm_financials=1, perm_photos=1
WHERE `role` IN ('admin','manager');
