feat: M2 database migration runner with Phinx and initial schema
This commit is contained in:
1 parent
d3e8cf8fae
commit
93d991703c
20 files changed
+2000
-14
No files matched your search
@@ -0,0 +1,31 @@
|
||||
<?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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user