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');
+ }
}
}
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');
+ }
}
}