From f7b919e6dd1af979c171b4ee1938b89e39fcee62 Mon Sep 17 00:00:00 2001 From: bencroker Date: Mon, 5 Aug 2024 13:55:45 +0200 Subject: [PATCH] Make DB migration more robust --- ...m240709_120000_add_fieldinstanceuid_column.php} | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) rename src/migrations/{m240709_120000_alter_fieldid_column.php => m240709_120000_add_fieldinstanceuid_column.php} (53%) diff --git a/src/migrations/m240709_120000_alter_fieldid_column.php b/src/migrations/m240709_120000_add_fieldinstanceuid_column.php similarity index 53% rename from src/migrations/m240709_120000_alter_fieldid_column.php rename to src/migrations/m240709_120000_add_fieldinstanceuid_column.php index 6efa9dda..e7e5d041 100644 --- a/src/migrations/m240709_120000_alter_fieldid_column.php +++ b/src/migrations/m240709_120000_add_fieldinstanceuid_column.php @@ -6,7 +6,7 @@ use putyourlightson\blitz\records\ElementFieldCacheRecord; use putyourlightson\blitz\records\ElementQueryFieldRecord; -class m240709_120000_alter_fieldid_column extends Migration +class m240709_120000_add_fieldinstanceuid_column extends Migration { /** * @inheritdoc @@ -15,18 +15,14 @@ public function safeUp(): bool { if ($this->db->columnExists(ElementFieldCacheRecord::tableName(), 'fieldId')) { ElementFieldCacheRecord::deleteAll(); - - $this->dropForeignKeyIfExists(ElementFieldCacheRecord::tableName(), 'fieldId'); - $this->renameColumn(ElementFieldCacheRecord::tableName(), 'fieldId', 'fieldInstanceUid'); - $this->alterColumn(ElementFieldCacheRecord::tableName(), 'fieldInstanceUid', $this->uid()); + $this->dropColumn(ElementFieldCacheRecord::tableName(), 'fieldId'); + $this->addColumn(ElementFieldCacheRecord::tableName(), 'fieldInstanceUid', $this->uid()); } if ($this->db->columnExists(ElementQueryFieldRecord::tableName(), 'fieldId')) { ElementQueryFieldRecord::deleteAll(); - - $this->dropForeignKeyIfExists(ElementQueryFieldRecord::tableName(), 'fieldId'); - $this->renameColumn(ElementQueryFieldRecord::tableName(), 'fieldId', 'fieldInstanceUid'); - $this->alterColumn(ElementQueryFieldRecord::tableName(), 'fieldInstanceUid', $this->uid()); + $this->dropColumn(ElementQueryFieldRecord::tableName(), 'fieldId'); + $this->addColumn(ElementQueryFieldRecord::tableName(), 'fieldInstanceUid', $this->uid()); } return true;