table('import_jobs', ['id' => 'id', 'primary_key' => 'id']) ->addColumn('source_path', 'text', ['null' => false]) // Status: Pending, Scanning, Copying, Completed, Failed, Cancelled ->addColumn('status', 'string', ['limit' => 32, 'default' => 'Pending']) ->addColumn('total_files', 'integer', ['null' => false, 'default' => 0, 'signed' => false]) ->addColumn('processed_files', 'integer', ['null' => false, 'default' => 0, 'signed' => false]) ->addColumn('total_bytes', 'biginteger', ['null' => false, 'default' => 0, 'signed' => false]) ->addColumn('copied_bytes', 'biginteger', ['null' => false, 'default' => 0, 'signed' => false]) ->addColumn('started_at', 'timestamp', ['null' => true, 'timezone' => true]) ->addColumn('completed_at', 'timestamp', ['null' => true, 'timezone' => true]) ->addColumn('created_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'timezone' => true]) ->addIndex(['status'], ['name' => 'idx_import_jobs_status']) ->addIndex(['created_at'], ['name' => 'idx_import_jobs_created_at']) ->create(); // Import items - per-file tracking $this->table('import_items', ['id' => 'id', 'primary_key' => 'id']) ->addColumn('job_id', 'integer', ['null' => false, 'signed' => false]) ->addColumn('source_path', 'text', ['null' => false]) ->addColumn('managed_path', 'text', ['null' => true]) ->addColumn('model_id', 'integer', ['null' => true, 'signed' => false]) ->addColumn('hash', 'string', ['limit' => 64, 'null' => true]) // SHA-256 hex ->addColumn('size', 'biginteger', ['null' => true, 'signed' => false]) // Status: Pending, Copying, Completed, Failed, Skipped ->addColumn('status', 'string', ['limit' => 32, 'default' => 'Pending']) ->addColumn('failure_reason', 'text', ['null' => true]) ->addColumn('started_at', 'timestamp', ['null' => true, 'timezone' => true]) ->addColumn('completed_at', 'timestamp', ['null' => true, 'timezone' => true]) ->addForeignKey('job_id', 'import_jobs', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) ->addForeignKey('model_id', 'models', 'id', ['delete' => 'SET NULL', 'update' => 'NO_ACTION']) ->addIndex(['job_id', 'status'], ['name' => 'idx_import_items_job_status']) ->addIndex(['job_id', 'managed_path'], ['name' => 'idx_import_items_job_path']) ->addIndex(['hash'], ['name' => 'idx_import_items_hash']) ->create(); } }