Ensure job_roles table exists before job_sub_roles migration

This commit is contained in:
2026-06-05 14:47:11 +02:00
parent e5bf546ae7
commit 789c547bc7
@@ -8,67 +8,117 @@ final class CreateJobSubRolesTable extends AbstractMigration
{ {
public function change(): void public function change(): void
{ {
$table = $this->table('job_sub_roles', [ if (!$this->hasTable('job_roles')) {
'id' => false, $rolesTable = $this->table('job_roles', [
'primary_key' => ['id'], 'id' => false,
'collation' => 'utf8mb4_unicode_ci', 'primary_key' => ['id'],
'encoding' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci',
]); 'encoding' => 'utf8mb4',
]);
$table $rolesTable
->addColumn('id', 'integer', [ ->addColumn('id', 'integer', [
'identity' => true, 'identity' => true,
'signed' => false, 'signed' => false,
]) ])
->addColumn('job_role_id', 'integer', [ ->addColumn('name', 'string', [
'signed' => false, 'limit' => 255,
'null' => false, 'null' => false,
]) ])
->addColumn('name', 'string', [ ->addColumn('description', 'text', [
'limit' => 255, 'null' => true,
'null' => false, 'default' => null,
]) ])
->addColumn('description', 'text', [ ->addColumn('sort_order', 'integer', [
'null' => true, 'signed' => false,
'default' => null, 'null' => false,
]) 'default' => 999,
->addColumn('sort_order', 'integer', [ ])
'signed' => false, ->addColumn('is_active', 'boolean', [
'null' => false, 'null' => false,
'default' => 999, 'default' => 1,
]) ])
->addColumn('is_active', 'boolean', [ ->addColumn('created_at', 'timestamp', [
'null' => false, 'null' => true,
'default' => 1, 'default' => 'CURRENT_TIMESTAMP',
]) ])
->addColumn('created_at', 'timestamp', [ ->addColumn('updated_at', 'timestamp', [
'null' => true, 'null' => true,
'default' => 'CURRENT_TIMESTAMP', 'default' => 'CURRENT_TIMESTAMP',
]) 'update' => 'CURRENT_TIMESTAMP',
->addColumn('updated_at', 'timestamp', [ ])
'null' => true, ->addIndex(['is_active'], [
'default' => 'CURRENT_TIMESTAMP', 'name' => 'idx_job_roles_is_active',
'update' => 'CURRENT_TIMESTAMP', ])
]) ->addIndex(['sort_order'], [
->addIndex(['job_role_id'], [ 'name' => 'idx_job_roles_sort_order',
'name' => 'idx_job_sub_roles_job_role_id', ])
]) ->create();
->addIndex(['is_active'], [ }
'name' => 'idx_job_sub_roles_is_active',
]) if (!$this->hasTable('job_sub_roles')) {
->addIndex(['sort_order'], [ $table = $this->table('job_sub_roles', [
'name' => 'idx_job_sub_roles_sort_order', 'id' => false,
]) 'primary_key' => ['id'],
->addForeignKey( 'collation' => 'utf8mb4_unicode_ci',
'job_role_id', 'encoding' => 'utf8mb4',
'job_roles', ]);
'id',
[ $table
'delete' => 'CASCADE', ->addColumn('id', 'integer', [
'update' => 'CASCADE', 'identity' => true,
'constraint' => 'fk_job_sub_roles_job_role', 'signed' => false,
] ])
) ->addColumn('job_role_id', 'integer', [
->create(); 'signed' => false,
'null' => false,
])
->addColumn('name', 'string', [
'limit' => 255,
'null' => false,
])
->addColumn('description', 'text', [
'null' => true,
'default' => null,
])
->addColumn('sort_order', 'integer', [
'signed' => false,
'null' => false,
'default' => 999,
])
->addColumn('is_active', 'boolean', [
'null' => false,
'default' => 1,
])
->addColumn('created_at', 'timestamp', [
'null' => true,
'default' => 'CURRENT_TIMESTAMP',
])
->addColumn('updated_at', 'timestamp', [
'null' => true,
'default' => 'CURRENT_TIMESTAMP',
'update' => 'CURRENT_TIMESTAMP',
])
->addIndex(['job_role_id'], [
'name' => 'idx_job_sub_roles_job_role_id',
])
->addIndex(['is_active'], [
'name' => 'idx_job_sub_roles_is_active',
])
->addIndex(['sort_order'], [
'name' => 'idx_job_sub_roles_sort_order',
])
->addForeignKey(
'job_role_id',
'job_roles',
'id',
[
'delete' => 'CASCADE',
'update' => 'CASCADE',
'constraint' => 'fk_job_sub_roles_job_role',
]
)
->create();
}
} }
} }