CREATE TABLE IF NOT EXISTS documents (
  id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  filename VARCHAR(255) NOT NULL,
  filepath VARCHAR(1024) NOT NULL,
  title VARCHAR(512) NULL,
  doc_type VARCHAR(120) NULL,
  filesize BIGINT(20) NULL,
  owner_user_id BIGINT(20) UNSIGNED NULL,
  current_version_id BIGINT(20) UNSIGNED NULL,
  status ENUM('active','archived','deleted') NOT NULL DEFAULT 'active',
  created_by BIGINT(20) UNSIGNED NOT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_status (status),
  KEY idx_doc_type (doc_type),
  KEY idx_created_at (created_at),
  KEY idx_title (title),
  KEY idx_owner (owner_user_id)
);
