65 lines
2.0 KiB
PHP
65 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class AddFunctionsToScadDeadlines extends AbstractMigration
|
|
{
|
|
public function change(): void
|
|
{
|
|
$this->table('scad_functions', [
|
|
'id' => false,
|
|
'primary_key' => ['id'],
|
|
'collation' => 'utf8mb4_unicode_ci',
|
|
'encoding' => 'utf8mb4',
|
|
])
|
|
->addColumn('id', 'integer', [
|
|
'identity' => true,
|
|
'signed' => false,
|
|
])
|
|
->addColumn('name', 'string', [
|
|
'limit' => 255,
|
|
'null' => false,
|
|
])
|
|
->addColumn('description', 'text', [
|
|
'null' => true,
|
|
])
|
|
->addColumn('status', 'string', [
|
|
'limit' => 20,
|
|
'null' => false,
|
|
'default' => 'active',
|
|
])
|
|
->addColumn('created_at', 'timestamp', [
|
|
'null' => false,
|
|
'default' => 'CURRENT_TIMESTAMP',
|
|
])
|
|
->addColumn('updated_at', 'timestamp', [
|
|
'null' => false,
|
|
'default' => 'CURRENT_TIMESTAMP',
|
|
'update' => 'CURRENT_TIMESTAMP',
|
|
])
|
|
->addIndex(['name'], [
|
|
'unique' => true,
|
|
'name' => 'uniq_scad_functions_name',
|
|
])
|
|
->create();
|
|
|
|
$this->table('scad_deadlines')
|
|
->addColumn('function_id', 'integer', [
|
|
'signed' => false,
|
|
'null' => true,
|
|
'after' => 'subject_id',
|
|
])
|
|
->addIndex(['function_id'], [
|
|
'name' => 'idx_scad_deadlines_function_id',
|
|
])
|
|
->addForeignKey('function_id', 'scad_functions', 'id', [
|
|
'delete' => 'SET_NULL',
|
|
'update' => 'CASCADE',
|
|
'constraint' => 'fk_scad_deadlines_function',
|
|
])
|
|
->update();
|
|
}
|
|
}
|