CREATE TABLE IF NOT EXISTS `entity_documents` (
  `id` text PRIMARY KEY NOT NULL,
  `entity_type` text NOT NULL,
  `entity_id` text NOT NULL,
  `category` text NOT NULL,
  `document_no` text NOT NULL DEFAULT '',
  `issue_date` text NOT NULL DEFAULT '',
  `expiry_date` text NOT NULL DEFAULT '',
  `file_name` text NOT NULL,
  `object_key` text NOT NULL,
  `content_type` text NOT NULL,
  `size_bytes` integer NOT NULL DEFAULT 0,
  `status` text NOT NULL DEFAULT 'Valide',
  `uploaded_by` text NOT NULL,
  `created_at` text NOT NULL,
  `updated_at` text NOT NULL
);
CREATE INDEX IF NOT EXISTS `idx_entity_documents_owner` ON `entity_documents` (`entity_type`,`entity_id`,`category`);
CREATE INDEX IF NOT EXISTS `idx_entity_documents_expiry` ON `entity_documents` (`expiry_date`,`status`);
