From 00e7e377ace88498fa1170cb48c3caff6309f973 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sat, 21 Mar 2026 15:57:15 +0530 Subject: [PATCH] Make GST insurance migration idempotent for existing columns --- ...2-08-000002_AddGstAgreementToInsurance.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/app/Database/Migrations/2026-02-08-000002_AddGstAgreementToInsurance.php b/app/Database/Migrations/2026-02-08-000002_AddGstAgreementToInsurance.php index faf4d2a..09bccf9 100644 --- a/app/Database/Migrations/2026-02-08-000002_AddGstAgreementToInsurance.php +++ b/app/Database/Migrations/2026-02-08-000002_AddGstAgreementToInsurance.php @@ -8,6 +8,10 @@ class AddGstAgreementToInsurance extends Migration { public function up(): void { + if (! $this->db->tableExists('hc_insurance')) { + return; + } + $fields = [ 'gst_no' => [ 'type' => 'VARCHAR', @@ -24,11 +28,28 @@ class AddGstAgreementToInsurance extends Migration ], ]; - $this->forge->addColumn('hc_insurance', $fields); + $addFields = []; + foreach ($fields as $name => $definition) { + if (! $this->db->fieldExists($name, 'hc_insurance')) { + $addFields[$name] = $definition; + } + } + + if (! empty($addFields)) { + $this->forge->addColumn('hc_insurance', $addFields); + } } public function down(): void { - $this->forge->dropColumn('hc_insurance', ['gst_no', 'agreement_start_date', 'agreement_end_date']); + if (! $this->db->tableExists('hc_insurance')) { + return; + } + + foreach (['gst_no', 'agreement_start_date', 'agreement_end_date'] as $column) { + if ($this->db->fieldExists($column, 'hc_insurance')) { + $this->forge->dropColumn('hc_insurance', $column); + } + } } }