diff --git a/app/Database/Migrations/2024-11-05-000700_AddBatchNumberToReimbursements.php b/app/Database/Migrations/2024-11-05-000700_AddBatchNumberToReimbursements.php index 20d94c3..94d9c80 100644 --- a/app/Database/Migrations/2024-11-05-000700_AddBatchNumberToReimbursements.php +++ b/app/Database/Migrations/2024-11-05-000700_AddBatchNumberToReimbursements.php @@ -8,6 +8,10 @@ class AddBatchNumberToReimbursements extends Migration { public function up() { + if (! $this->db->tableExists('reimbursements') || $this->db->fieldExists('batch_number', 'reimbursements')) { + return; + } + $fields = [ 'batch_number' => [ 'type' => 'INT', @@ -24,7 +28,8 @@ class AddBatchNumberToReimbursements extends Migration public function down() { - $this->forge->dropColumn('reimbursements', 'batch_number'); + if ($this->db->tableExists('reimbursements') && $this->db->fieldExists('batch_number', 'reimbursements')) { + $this->forge->dropColumn('reimbursements', 'batch_number'); + } } } - diff --git a/app/Database/Migrations/2024-11-07-000800_AddYearlyBatchNumberToReimbursementBatches.php b/app/Database/Migrations/2024-11-07-000800_AddYearlyBatchNumberToReimbursementBatches.php index a44845d..d95b902 100644 --- a/app/Database/Migrations/2024-11-07-000800_AddYearlyBatchNumberToReimbursementBatches.php +++ b/app/Database/Migrations/2024-11-07-000800_AddYearlyBatchNumberToReimbursementBatches.php @@ -8,25 +8,33 @@ class AddYearlyBatchNumberToReimbursementBatches extends Migration { public function up() { - $fields = [ - 'yearly_batch_number' => [ - 'type' => 'INT', - 'constraint' => 11, - 'unsigned' => true, - 'default' => 0, - 'null' => false, - 'after' => 'title', - ], - ]; + if (! $this->db->tableExists('reimbursement_batches')) { + return; + } - $this->forge->addColumn('reimbursement_batches', $fields); + if (! $this->db->fieldExists('yearly_batch_number', 'reimbursement_batches')) { + $fields = [ + 'yearly_batch_number' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => true, + 'default' => 0, + 'null' => false, + 'after' => 'title', + ], + ]; + + $this->forge->addColumn('reimbursement_batches', $fields); + } $this->fillExistingBatchNumbers(); } public function down() { - $this->forge->dropColumn('reimbursement_batches', 'yearly_batch_number'); + if ($this->db->tableExists('reimbursement_batches') && $this->db->fieldExists('yearly_batch_number', 'reimbursement_batches')) { + $this->forge->dropColumn('reimbursement_batches', 'yearly_batch_number'); + } } private function fillExistingBatchNumbers(): void