+++ /dev/null
-<?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);
- }
- }
-}
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'
+ );
}
}
{
$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);
}
}
+++ /dev/null
-<?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);
- }
- }
-}