33 lines
1.4 KiB
PHP
33 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
/**
|
|
* Schema: uploaded thumbnails.
|
|
*
|
|
* Thumbnails are user-uploaded images associated with models.
|
|
* They are stored in the managed library under a thumbnails/ subdirectory
|
|
* and tracked separately from model files.
|
|
*/
|
|
final class CreateThumbnails extends AbstractMigration
|
|
{
|
|
public function change(): void
|
|
{
|
|
$this->table('thumbnails', ['id' => 'id', 'primary_key' => 'id'])
|
|
->addColumn('model_id', 'integer', ['null' => false, 'signed' => false])
|
|
->addColumn('managed_path', 'text', ['null' => false])
|
|
->addColumn('hash', 'string', ['limit' => 64, 'null' => false]) // SHA-256 hex
|
|
->addColumn('size', 'biginteger', ['null' => false, 'signed' => false])
|
|
->addColumn('mime_type', 'string', ['limit' => 128, 'null' => false])
|
|
->addColumn('width', 'integer', ['null' => true, 'signed' => false])
|
|
->addColumn('height', 'integer', ['null' => true, 'signed' => false])
|
|
->addColumn('uploaded_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'timezone' => true])
|
|
->addForeignKey('model_id', 'models', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
|
->addIndex(['model_id'], ['name' => 'idx_thumbnails_model_id'])
|
|
->addIndex(['hash'], ['unique' => true, 'name' => 'idx_thumbnails_hash'])
|
|
->create();
|
|
}
|
|
}
|