]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-396: убрать индексы из миграций store_type/city_store_params, добавить идемпотент...
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 3 Jun 2026 06:50:03 +0000 (09:50 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 3 Jun 2026 06:50:03 +0000 (09:50 +0300)
Таблицы небольшие — индексы не дают выигрыша.
Проверка существования колонки в safeUp/safeDown предотвращает
падение при повторных накатах и откатах миграций.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
erp24/migrations/m260601_100000_add_code_to_store_type.php
erp24/migrations/m260601_110000_add_is_active_to_city_store_params.php

index ad845efb470af38de75311b0fc9bf317249239d0..5012e66038917ff613dcc8dbed2f5e74f25918fd 100644 (file)
@@ -11,22 +11,24 @@ use yii\db\Migration;
 class m260601_100000_add_code_to_store_type extends Migration
 {
     private const TABLE = 'erp24.store_type';
-    private const INDEX = 'idx_store_type_code';
 
     public function safeUp(): void
     {
-        $this->addColumn(
-            self::TABLE,
-            'code',
-            $this->string(50)->null()->comment('Slug-код типа магазина (large, small, medium, xlarge, na, flagship, kiosk, ...)')
-        );
-
-        $this->createIndex(self::INDEX, self::TABLE, 'code', true);
+        $schema = $this->db->getTableSchema(self::TABLE, true);
+        if ($schema !== null && $schema->getColumn('code') === null) {
+            $this->addColumn(
+                self::TABLE,
+                'code',
+                $this->string(50)->null()->comment('Slug-код типа магазина (large, small, medium, xlarge, ...)')
+            );
+        }
     }
 
     public function safeDown(): void
     {
-        $this->dropIndex(self::INDEX, self::TABLE);
-        $this->dropColumn(self::TABLE, 'code');
+        $schema = $this->db->getTableSchema(self::TABLE, true);
+        if ($schema !== null && $schema->getColumn('code') !== null) {
+            $this->dropColumn(self::TABLE, 'code');
+        }
     }
 }
index eb76242d6fbdcdc9855a6be876d3e4346c753003..d543866c5b3fe6262725832e127220cd7acf2c71 100644 (file)
@@ -15,26 +15,24 @@ use yii\db\Migration;
 class m260601_110000_add_is_active_to_city_store_params extends Migration
 {
     private const TABLE = 'city_store_params';
-    private const INDEX = 'idx_city_store_params_inactive';
 
     public function safeUp(): void
     {
-        $this->addColumn(
-            self::TABLE,
-            'is_active',
-            $this->boolean()->notNull()->defaultValue(true)->comment('Активен ли магазин (TRUE=да, FALSE=нет)')
-        );
-
-        // Partial index: только неактивные магазины (меньшинство).
-        // Полный индекс на boolean-колонке PostgreSQL не использует из-за низкой кардинальности.
-        $this->execute(
-            'CREATE INDEX ' . self::INDEX . ' ON ' . self::TABLE . ' (store_id) WHERE is_active = false'
-        );
+        $schema = $this->db->getTableSchema(self::TABLE, true);
+        if ($schema !== null && $schema->getColumn('is_active') === null) {
+            $this->addColumn(
+                self::TABLE,
+                'is_active',
+                $this->boolean()->notNull()->defaultValue(true)->comment('Активен ли магазин (TRUE=да, FALSE=нет)')
+            );
+        }
     }
 
     public function safeDown(): void
     {
-        $this->execute('DROP INDEX IF EXISTS ' . self::INDEX);
-        $this->dropColumn(self::TABLE, 'is_active');
+        $schema = $this->db->getTableSchema(self::TABLE, true);
+        if ($schema !== null && $schema->getColumn('is_active') !== null) {
+            $this->dropColumn(self::TABLE, 'is_active');
+        }
     }
 }