]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Создание миграции справочника
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 16 Jan 2025 14:11:32 +0000 (17:11 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 16 Jan 2025 14:11:32 +0000 (17:11 +0300)
erp24/migrations/m250116_112712_create_store_region_list_table.php [deleted file]
erp24/migrations/m250116_112743_create_store_city_list_table.php
erp24/migrations/m250116_112755_create_store_district_list_table.php [deleted file]

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 (file)
index 810f7ef..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-
-use yii\db\Migration;
-
-/**
- * Handles the creation of table `{{%store_region_list}}`.
- */
-class m250116_112712_create_store_region_list_table extends Migration
-{
-    const TABLE_NAME = 'erp24.store_region_list';
-    /**
-     * {@inheritdoc}
-     */
-    public function safeUp()
-    {
-        $tableSchema = $this->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);
-        }
-    }
-}
index ad7231d1aaa9b4c1a42f9febe6f97b2c38d26b4c..bb29d302c47c0ccbc7040e7f547105628f820f54 100644 (file)
@@ -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 (file)
index 8dcdf3f..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-use yii\db\Migration;
-
-/**
- * Handles the creation of table `{{%store_district_list}}`.
- */
-class m250116_112755_create_store_district_list_table extends Migration
-{
-    const TABLE_NAME = 'erp24.store_district_list';
-    /**
-     * {@inheritdoc}
-     */
-    public function safeUp()
-    {
-        $tableSchema = $this->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);
-        }
-    }
-}