Files
MeshVault/db/migrations/20261011120003_create_files.php
T

39 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
/**
* Schema: files with hash, size, and lifecycle status.
*
* Files belong to a model and represent physical files in the managed library.
* Each file has a SHA-256 hash for change detection, size for space tracking,
* and a lifecycle status (Present, Missing, Updated, Duplicate).
* The managed path is relative to the library root.
*/
final class CreateFiles extends AbstractMigration
{
public function change(): void
{
$this->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();
}
}