table('files', ['id' => 'id', 'primary_key' => 'id']) ->addColumn('model_id', 'integer', ['null' => false, 'signed' => false]) ->addColumn('folder_id', 'integer', ['null' => false, 'signed' => false]) ->addColumn('name', 'string', ['limit' => 255]) ->addColumn('managed_path', 'text', ['null' => false]) ->addColumn('hash', 'string', ['limit' => 64, 'null' => true]) // SHA-256 hex ->addColumn('size', 'biginteger', ['null' => true, 'signed' => false]) ->addColumn('mime_type', 'string', ['limit' => 128, 'null' => true]) ->addColumn('status', 'string', ['limit' => 32, 'default' => 'Present']) ->addColumn('added_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'timezone' => true]) ->addColumn('updated_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'timezone' => true]) ->addForeignKey('model_id', 'models', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) ->addForeignKey('folder_id', 'folders', 'id', ['delete' => 'RESTRICT', 'update' => 'NO_ACTION']) ->addIndex(['model_id', 'managed_path'], ['unique' => true, 'name' => 'idx_files_model_path']) ->addIndex(['hash'], ['name' => 'idx_files_hash']) ->addIndex(['status'], ['name' => 'idx_files_status']) ->addIndex(['folder_id'], ['name' => 'idx_files_folder_id']) ->create(); } }