From 8efd2b4f949d86c45e0f4a747c05d43f9644199b Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 3 Jun 2026 09:50:03 +0300 Subject: [PATCH] =?utf8?q?ERP-396:=20=D1=83=D0=B1=D1=80=D0=B0=D1=82=D1=8C?= =?utf8?q?=20=D0=B8=D0=BD=D0=B4=D0=B5=D0=BA=D1=81=D1=8B=20=D0=B8=D0=B7=20?= =?utf8?q?=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20store=5Ftype/?= =?utf8?q?city=5Fstore=5Fparams,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?utf8?q?=D1=82=D1=8C=20=D0=B8=D0=B4=D0=B5=D0=BC=D0=BF=D0=BE=D1=82=D0=B5?= =?utf8?q?=D0=BD=D1=82=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Таблицы небольшие — индексы не дают выигрыша. Проверка существования колонки в safeUp/safeDown предотвращает падение при повторных накатах и откатах миграций. Co-Authored-By: Claude Sonnet 4.6 --- .../m260601_100000_add_code_to_store_type.php | 22 +++++++++------- ...000_add_is_active_to_city_store_params.php | 26 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/erp24/migrations/m260601_100000_add_code_to_store_type.php b/erp24/migrations/m260601_100000_add_code_to_store_type.php index ad845efb..5012e660 100644 --- a/erp24/migrations/m260601_100000_add_code_to_store_type.php +++ b/erp24/migrations/m260601_100000_add_code_to_store_type.php @@ -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'); + } } } diff --git a/erp24/migrations/m260601_110000_add_is_active_to_city_store_params.php b/erp24/migrations/m260601_110000_add_is_active_to_city_store_params.php index eb76242d..d543866c 100644 --- a/erp24/migrations/m260601_110000_add_is_active_to_city_store_params.php +++ b/erp24/migrations/m260601_110000_add_is_active_to_city_store_params.php @@ -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'); + } } } -- 2.39.5