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

diff --git a/erp24/migrations/m250116_112712_create_store_region_list_table.php b/erp24/migrations/m250116_112712_create_store_region_list_table.php
new file mode 100644 (file)
index 0000000..810f7ef
--- /dev/null
@@ -0,0 +1,43 @@
+<?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);
+        }
+    }
+}
diff --git a/erp24/migrations/m250116_112743_create_store_city_list_table.php b/erp24/migrations/m250116_112743_create_store_city_list_table.php
new file mode 100644 (file)
index 0000000..ad7231d
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%store_city_list}}`.
+ */
+class m250116_112743_create_store_city_list_table extends Migration
+{
+    const TABLE_NAME = 'erp24.store_city_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('Город'),
+                '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_112755_create_store_district_list_table.php b/erp24/migrations/m250116_112755_create_store_district_list_table.php
new file mode 100644 (file)
index 0000000..8dcdf3f
--- /dev/null
@@ -0,0 +1,49 @@
+<?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);
+        }
+    }
+}