-- Run only the ALTER statements that your existing database still needs.
ALTER TABLE companies
  ADD COLUMN IF NOT EXISTS notification_email VARCHAR(190) NULL AFTER api_key,
  ADD COLUMN IF NOT EXISTS is_active TINYINT(1) NOT NULL DEFAULT 1 AFTER notification_email;

CREATE TABLE IF NOT EXISTS audit_log (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  company_id BIGINT UNSIGNED NOT NULL,
  review_id BIGINT UNSIGNED NULL,
  action VARCHAR(50) NOT NULL,
  actor VARCHAR(50) NOT NULL,
  ip_hash CHAR(64) NULL,
  metadata LONGTEXT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_audit_company_created (company_id, created_at),
  KEY idx_audit_review (review_id),
  CONSTRAINT fk_audit_company FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE,
  CONSTRAINT fk_audit_review FOREIGN KEY (review_id) REFERENCES reviews(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Set the owner email for Jhenn Cleaning:
UPDATE companies
SET notification_email = 'CHANGE_TO_OWNER_EMAIL@example.com', is_active = 1
WHERE id = 1;
