]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление проверки в миграцию
authorvladfo <fvv2011@gmail.com>
Mon, 21 Oct 2024 10:04:59 +0000 (13:04 +0300)
committervladfo <fvv2011@gmail.com>
Mon, 21 Oct 2024 10:04:59 +0000 (13:04 +0300)
erp24/migrations/m241018_065706_alter_table_city_store_drop_column_cluster_id.php

index 0ec9fc31a72d85ac00bf7703e15e5a7f74b74744..af59518d45a28bf239434fd92aee7df1319807c6 100644 (file)
@@ -11,13 +11,18 @@ class m241018_065706_alter_table_city_store_drop_column_cluster_id extends Migra
      * {@inheritdoc}
      */
     const TABLE_NAME = "city_store";
+    const COLUMN_NAME = "cluster_id";
 
     /**
      * {@inheritdoc}
      */
     public function safeUp()
     {
-        $this->dropColumn(self::TABLE_NAME, 'cluster_id');
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+        if (isset($tableSchema->columns[self::COLUMN_NAME])) {
+            $this->dropColumn(self::TABLE_NAME, self::COLUMN_NAME);
+        }
     }
 
     /**
@@ -27,9 +32,12 @@ class m241018_065706_alter_table_city_store_drop_column_cluster_id extends Migra
     {
 
 
-        $this->addColumn(self::TABLE_NAME, 'cluster_id', $this->integer()->null()->after('administrator_id'));
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
 
-        $this->update(self::TABLE_NAME, ['cluster_id' => null]);
+        if (!isset($tableSchema->columns[self::COLUMN_NAME])) {
+            $this->addColumn(self::TABLE_NAME, self::COLUMN_NAME, $this->integer()->null()->after('administrator_id'));
+            $this->update(self::TABLE_NAME, [self::COLUMN_NAME => null]);
+        }
 
     }