-- ZT Mobile - Upgrade Patch (run once)
-- 1) Optional: PIN Lock support (App Lock)
CREATE TABLE IF NOT EXISTS user_security (
  user_id INT UNSIGNED NOT NULL,
  pin_hash VARCHAR(255) NULL,
  pin_enabled TINYINT(1) NOT NULL DEFAULT 0,
  last_unlock_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL,
  PRIMARY KEY (user_id),
  CONSTRAINT fk_user_security_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 2) Optional: FULLTEXT search index (skip if already exists)
-- If you already have ft_brand_model, this will fail with duplicate key name; then ignore.
-- ALTER TABLE device_catalog ADD FULLTEXT KEY ft_brand_model (brand, model);
