26 lines
1.3 KiB
PHP
26 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class CreateWorkSheetPackages extends AbstractMigration
|
|
{
|
|
public function change(): void
|
|
{
|
|
$this->table('work_sheet_packages', ['id' => 'id'])
|
|
->addColumn('worksheet_id', 'integer', ['limit' => 11])
|
|
->addColumn('package_code', 'integer', ['limit' => 11, 'comment' => 'FK -> packaging_items.id'])
|
|
->addColumn('package_position', 'integer', ['default' => 1])
|
|
->addColumn('created_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP'])
|
|
->addColumn('updated_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP'])
|
|
->addIndex(['worksheet_id'], ['name' => 'idx_wsp_ws'])
|
|
->addIndex(['package_code'], ['name' => 'idx_wsp_pkg'])
|
|
->addIndex(['worksheet_id', 'package_code'], ['unique' => true, 'name' => 'uk_wsp_ws_pkg'])
|
|
->addIndex(['worksheet_id', 'package_position'], ['unique' => true, 'name' => 'uk_wsp_ws_position'])
|
|
->addForeignKey('worksheet_id', 'work_sheets', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
|
|
->addForeignKey('package_code', 'packaging_items', 'id', ['update' => 'CASCADE'])
|
|
->create();
|
|
}
|
|
}
|