diff --git a/db/migrations/20260603183520_create_job_sub_roles_table.php b/db/migrations/20260603183520_create_job_sub_roles_table.php index c0c5bcc..b1d85ed 100644 --- a/db/migrations/20260603183520_create_job_sub_roles_table.php +++ b/db/migrations/20260603183520_create_job_sub_roles_table.php @@ -8,67 +8,117 @@ final class CreateJobSubRolesTable extends AbstractMigration { public function change(): void { - $table = $this->table('job_sub_roles', [ - 'id' => false, - 'primary_key' => ['id'], - 'collation' => 'utf8mb4_unicode_ci', - 'encoding' => 'utf8mb4', - ]); + if (!$this->hasTable('job_roles')) { + $rolesTable = $this->table('job_roles', [ + 'id' => false, + 'primary_key' => ['id'], + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + ]); - $table - ->addColumn('id', 'integer', [ - 'identity' => true, - 'signed' => false, - ]) - ->addColumn('job_role_id', 'integer', [ - '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(); + $rolesTable + ->addColumn('id', 'integer', [ + 'identity' => true, + 'signed' => 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(['is_active'], [ + 'name' => 'idx_job_roles_is_active', + ]) + ->addIndex(['sort_order'], [ + 'name' => 'idx_job_roles_sort_order', + ]) + ->create(); + } + + if (!$this->hasTable('job_sub_roles')) { + $table = $this->table('job_sub_roles', [ + 'id' => false, + 'primary_key' => ['id'], + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + ]); + + $table + ->addColumn('id', 'integer', [ + 'identity' => true, + 'signed' => false, + ]) + ->addColumn('job_role_id', 'integer', [ + '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(); + } } }