Make GST insurance migration idempotent for existing columns
This commit is contained in:
parent
38093da3b9
commit
00e7e377ac
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user