32 lines
1.3 KiB
PHP
32 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
/**
|
|
* Initial schema: folders mirroring the managed library tree.
|
|
*
|
|
* Folders form a recursive tree structure where each folder has an optional
|
|
* parent folder. The root folder has parent_id = NULL. The path is stored
|
|
* as a materialized absolute path from the library root for efficient queries.
|
|
*/
|
|
final class CreateFolders extends AbstractMigration
|
|
{
|
|
public function change(): void
|
|
{
|
|
$this->table('folders', ['id' => 'id', 'primary_key' => 'id'])
|
|
->addColumn('parent_id', 'integer', ['null' => true, 'signed' => false])
|
|
->addColumn('name', 'string', ['limit' => 255])
|
|
->addColumn('path', 'text', ['null' => false])
|
|
->addColumn('added_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'timezone' => true])
|
|
->addForeignKey('parent_id', 'folders', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
|
->addIndex(['parent_id', 'name'], ['unique' => true, 'name' => 'idx_folders_parent_name'])
|
|
->addIndex(['path'], ['unique' => true, 'name' => 'idx_folders_path'])
|
|
->create();
|
|
|
|
// Root folder entry (will be created by application on first run)
|
|
// Application ensures root folder exists with path = '/' and parent_id = NULL
|
|
}
|
|
}
|