From: vladfo Date: Mon, 21 Oct 2024 10:04:59 +0000 (+0300) Subject: Добавление проверки в миграцию X-Git-Tag: 1.6~30^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=1dd63803474e21239c2196a56b6cd0609e272a59;p=erp24_rep%2Fyii-erp24%2F.git Добавление проверки в миграцию --- diff --git a/erp24/migrations/m241018_065706_alter_table_city_store_drop_column_cluster_id.php b/erp24/migrations/m241018_065706_alter_table_city_store_drop_column_cluster_id.php index 0ec9fc31..af59518d 100644 --- a/erp24/migrations/m241018_065706_alter_table_city_store_drop_column_cluster_id.php +++ b/erp24/migrations/m241018_065706_alter_table_city_store_drop_column_cluster_id.php @@ -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]); + } }