From: fomichev Date: Thu, 16 Jan 2025 14:11:32 +0000 (+0300) Subject: Создание миграции справочника X-Git-Tag: 1.7~68^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=0b5fd48ac7b64d36af79fa9079786e1fc2d6bddd;p=erp24_rep%2Fyii-erp24%2F.git Создание миграции справочника --- diff --git a/erp24/migrations/m250116_112712_create_store_region_list_table.php b/erp24/migrations/m250116_112712_create_store_region_list_table.php deleted file mode 100644 index 810f7ef8..00000000 --- a/erp24/migrations/m250116_112712_create_store_region_list_table.php +++ /dev/null @@ -1,43 +0,0 @@ -db->getTableSchema(self::TABLE_NAME); - - if (!isset($tableSchema)) { - $this->createTable(self::TABLE_NAME, [ - 'id' => $this->primaryKey()->comment('Первичный ключ'), - 'name' => $this->string()->notNull()->comment('Регион'), - 'code' => $this->integer()->notNull()->comment('Код региона'), - 'okrug' => $this->string()->notNull()->comment('Округ'), - 'created_at' => $this->dateTime() - ->notNull() - ->defaultExpression('CURRENT_TIMESTAMP') - ->comment('Дата создания записи'), - ]); - - } - } - - /** - * {@inheritdoc} - */ - public function safeDown() - { - $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); - if (isset($tableSchema)) { - $this->dropTable(self::TABLE_NAME); - } - } -} diff --git a/erp24/migrations/m250116_112743_create_store_city_list_table.php b/erp24/migrations/m250116_112743_create_store_city_list_table.php index ad7231d1..bb29d302 100644 --- a/erp24/migrations/m250116_112743_create_store_city_list_table.php +++ b/erp24/migrations/m250116_112743_create_store_city_list_table.php @@ -18,13 +18,24 @@ class m250116_112743_create_store_city_list_table extends Migration if (!isset($tableSchema)) { $this->createTable(self::TABLE_NAME, [ 'id' => $this->primaryKey()->comment('Первичный ключ'), - 'name' => $this->string()->notNull()->comment('Город'), + 'parent_id' => $this->integer()->null()->comment('Идентификатор родителя'), + 'name' => $this->string()->notNull()->comment('Название (регион, город, район)'), + 'type' => $this->string()->notNull()->comment('Тип (region, city, district)'), 'created_at' => $this->dateTime() ->notNull() ->defaultExpression('CURRENT_TIMESTAMP') ->comment('Дата создания записи'), ]); + $this->addForeignKey( + 'fk-store_city_list-parent_id', + self::TABLE_NAME, + 'parent_id', + self::TABLE_NAME, + 'id', + 'SET NULL', + 'SET NULL' + ); } } @@ -35,6 +46,7 @@ class m250116_112743_create_store_city_list_table extends Migration { $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); if (isset($tableSchema)) { + $this->dropForeignKey('fk-store_city_list-parent_id', self::TABLE_NAME); $this->dropTable(self::TABLE_NAME); } } diff --git a/erp24/migrations/m250116_112755_create_store_district_list_table.php b/erp24/migrations/m250116_112755_create_store_district_list_table.php deleted file mode 100644 index 8dcdf3f0..00000000 --- a/erp24/migrations/m250116_112755_create_store_district_list_table.php +++ /dev/null @@ -1,49 +0,0 @@ -db->getTableSchema(self::TABLE_NAME); - - if (!isset($tableSchema)) { - $this->createTable(self::TABLE_NAME, [ - 'id' => $this->primaryKey()->comment('Первичный ключ'), - 'name' => $this->string()->notNull()->comment('Район'), - 'city_id' => $this->integer()->notNull()->comment('ID города'), - 'created_at' => $this->dateTime() - ->notNull() - ->defaultExpression('CURRENT_TIMESTAMP') - ->comment('Дата создания записи'), - ]); - $this->addForeignKey( - 'fk-city_id', - self::TABLE_NAME, - 'city_id', - 'erp24.store_city_list', - 'id', - ); - - } - } - - /** - * {@inheritdoc} - */ - public function safeDown() - { - $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); - if (isset($tableSchema)) { - $this->dropTable(self::TABLE_NAME); - } - } -}