Skip to content

Commit

Permalink
Make DB migration more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Aug 5, 2024
1 parent 16c91aa commit f7b919e
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit f7b919e

Please sign in to comment.