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,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Schema: import jobs and per-file import items.
|
||||
*
|
||||
* Import jobs track the overall import operation with progress, totals,
|
||||
* and status. Import items represent individual files being imported,
|
||||
* with their source path, destination, status, and any failure reason.
|
||||
*/
|
||||
final class CreateImportJobs extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
// Import jobs - overall operation tracking
|
||||
$this->table('import_jobs', ['id' => 'id', 'primary_key' => 'id'])
|
||||
->addColumn('source_path', 'text', ['null' => false])
|
||||
// Status: Pending, Scanning, Copying, Completed, Failed, Cancelled
|
||||
->addColumn('status', 'string', ['limit' => 32, 'default' => 'Pending'])
|
||||
->addColumn('total_files', 'integer', ['null' => false, 'default' => 0, 'signed' => false])
|
||||
->addColumn('processed_files', 'integer', ['null' => false, 'default' => 0, 'signed' => false])
|
||||
->addColumn('total_bytes', 'biginteger', ['null' => false, 'default' => 0, 'signed' => false])
|
||||
->addColumn('copied_bytes', 'biginteger', ['null' => false, 'default' => 0, 'signed' => false])
|
||||
->addColumn('started_at', 'timestamp', ['null' => true, 'timezone' => true])
|
||||
->addColumn('completed_at', 'timestamp', ['null' => true, 'timezone' => true])
|
||||
->addColumn('created_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'timezone' => true])
|
||||
->addIndex(['status'], ['name' => 'idx_import_jobs_status'])
|
||||
->addIndex(['created_at'], ['name' => 'idx_import_jobs_created_at'])
|
||||
->create();
|
||||
|
||||
// Import items - per-file tracking
|
||||
$this->table('import_items', ['id' => 'id', 'primary_key' => 'id'])
|
||||
->addColumn('job_id', 'integer', ['null' => false, 'signed' => false])
|
||||
->addColumn('source_path', 'text', ['null' => false])
|
||||
->addColumn('managed_path', 'text', ['null' => true])
|
||||
->addColumn('model_id', 'integer', ['null' => true, 'signed' => false])
|
||||
->addColumn('hash', 'string', ['limit' => 64, 'null' => true]) // SHA-256 hex
|
||||
->addColumn('size', 'biginteger', ['null' => true, 'signed' => false])
|
||||
// Status: Pending, Copying, Completed, Failed, Skipped
|
||||
->addColumn('status', 'string', ['limit' => 32, 'default' => 'Pending'])
|
||||
->addColumn('failure_reason', 'text', ['null' => true])
|
||||
->addColumn('started_at', 'timestamp', ['null' => true, 'timezone' => true])
|
||||
->addColumn('completed_at', 'timestamp', ['null' => true, 'timezone' => true])
|
||||
->addForeignKey('job_id', 'import_jobs', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||
->addForeignKey('model_id', 'models', 'id', ['delete' => 'SET NULL', 'update' => 'NO_ACTION'])
|
||||
->addIndex(['job_id', 'status'], ['name' => 'idx_import_items_job_status'])
|
||||
->addIndex(['job_id', 'managed_path'], ['name' => 'idx_import_items_job_path'])
|
||||
->addIndex(['hash'], ['name' => 'idx_import_items_hash'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user