Make GST insurance migration idempotent for existing columns

This commit is contained in:
DevSoftTech Server 2026-03-21 15:57:15 +05:30
parent 38093da3b9
commit 00e7e377ac

View File

@ -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);
}
}
}
}