-- =============================================================================
-- Migration: workactivityitem_files (Multi-Dokumen Hasil Kerja per Item)
-- Sesuai model: apps/sapps/masters/workActivities/workActivityItemFile.model.js
-- Table name: workactivityitem_files (freezeTableName: true)
-- Purpose: Satu item aktivitas (workactivityitems) dapat punya banyak file bukti.
-- Safe:    CREATE TABLE IF NOT EXISTS; tidak mengubah/hapus tabel existing.
-- Run:     phpMyAdmin / MySQL — backup DB dulu jika perlu.
-- =============================================================================

-- Kolom mengikuti urutan dan definisi di WorkActivityItemFile model:
-- id, creation, modified, modified_by, owner, enabled,
-- workactivityitem_id, file_name, file_path, sort_order
CREATE TABLE IF NOT EXISTS `workactivityitem_files` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `creation` DATETIME NOT NULL,
  `modified` DATETIME NOT NULL,
  `modified_by` INT(11) NULL DEFAULT NULL,
  `owner` INT(11) NULL DEFAULT NULL,
  `enabled` TINYINT(1) NOT NULL DEFAULT 1,

  `workactivityitem_id` INT(11) NOT NULL,
  `file_name` VARCHAR(255) NULL DEFAULT NULL,
  `file_path` VARCHAR(500) NOT NULL,
  `sort_order` INT(11) NULL DEFAULT 0,

  PRIMARY KEY (`id`),
  INDEX `idx_workactivityitem_files_item_id` (`workactivityitem_id`),
  CONSTRAINT `fk_workactivityitem_files_item_id`
    FOREIGN KEY (`workactivityitem_id`) REFERENCES `workactivityitems` (`id`)
    ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
