]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
миграция
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 3 Oct 2025 14:22:01 +0000 (17:22 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 3 Oct 2025 14:22:01 +0000 (17:22 +0300)
erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php

index 8d4df58b2064984c18258522c75bb5941efab639..00060a676377e1194e79b3639527b2cdce317788 100644 (file)
@@ -14,16 +14,20 @@ class m250925_231312_craete_table_self_cost_product_dynamic extends Migration
      */
     public function safeUp()
     {
-        $this->createTable(self::TABLE_NAME, [
-            'id' => $this->bigPrimaryKey(),
-            'store_id' => $this->integer()->notNull(),
-            'product_guid' => $this->string()->notNull()->comment('product guid'),
-            'price' => $this->float()->notNull()->comment('price'),
-            'date_from' => $this->date()->notNull()->comment('Дата начала'),
-            'date_to' => $this->date()->defaultValue('2100-01-01')->notNull()->comment('Дата окончания'),
-            'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()')->comment('Дата создания записи'),
-            'updated_at' => $this->datetime()->null()->comment('Дата внесения записи'),
-        ]);
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+        if (!isset($tableSchema)) {
+            $this->createTable(self::TABLE_NAME, [
+                'id' => $this->bigPrimaryKey(),
+                'store_id' => $this->integer()->notNull(),
+                'product_guid' => $this->string()->notNull()->comment('product guid'),
+                'price' => $this->float()->notNull()->comment('price'),
+                'date_from' => $this->date()->notNull()->comment('Дата начала'),
+                'date_to' => $this->date()->defaultValue('2100-01-01')->notNull()->comment('Дата окончания'),
+                'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()')->comment('Дата создания записи'),
+                'updated_at' => $this->datetime()->null()->comment('Дата внесения записи'),
+            ]);
+        }
     }
 
     /**
@@ -31,6 +35,9 @@ class m250925_231312_craete_table_self_cost_product_dynamic extends Migration
      */
     public function safeDown()
     {
-        $this->dropTable(self::TABLE_NAME);
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+        if (isset($tableSchema)) {
+            $this->dropTable(self::TABLE_NAME);
+        }
     }
 }