File: /home/safarimaris/home/safarimaris/console/migrations/m161025_143525_dictionary.php
<?php
use yii\db\Migration;
class m161025_143525_dictionary extends Migration
{
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
//rename block
$this->renameTable('{{%fleet}}', '{{%dic_fleet}}');
$this->renameTable('{{%material}}', '{{%dic_material}}');
$this->batchInsert('{{%dic_material}}', ['name'], [
['Сталь'],
['Дерево'],
['Алюминий']
]);
//language
$this->createTable('{{%dic_language}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
$this->createTable('{{%entity_language_link}}', [
'entityId' => $this->integer()->notNull(),
'languageId' => $this->integer(),
], $tableOptions);
$this->addForeignKey('FK_entity_language_entity', '{{%entity_language_link}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_language_language', '{{%entity_language_link}}', 'languageId', '{{%dic_language}}', 'id', 'CASCADE', 'CASCADE');
$this->batchInsert('{{%dic_language}}', ['name'], [
['Английский'],
['Французский'],
['Немецкий'],
['Русский'],
['Украинский'],
['Другие']
]);
//document
$this->createTable('{{%dic_document}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
$this->createTable('{{%entity_document_link}}', [
'entityId' => $this->integer()->notNull(),
'documentId' => $this->integer(),
], $tableOptions);
$this->addForeignKey('FK_entity_document_entity', '{{%entity_document_link}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_document_document', '{{%entity_document_link}}', 'documentId', '{{%dic_document}}', 'id', 'CASCADE', 'CASCADE');
$this->batchInsert('{{%dic_document}}', ['name'], [
['Паспорт'],
['Дайвинг-сертификат'],
['Дата рождения'],
['Дата последнего дайва'],
['Логбук'],
['Дайверская страховка'],
['Количество дайвов в логбуке']
]);
//navigation
$this->createTable('{{%dic_navigation}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
$this->createTable('{{%entity_boat_navigation_link}}', [
'entityId' => $this->integer()->notNull(),
'navigationId' => $this->integer(),
], $tableOptions);
$this->addForeignKey('FK_entity_boat_navigation_entity', '{{%entity_boat_navigation_link}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_boat_navigation_navigation', '{{%entity_boat_navigation_link}}', 'navigationId', '{{%dic_navigation}}', 'id', 'CASCADE', 'CASCADE');
$this->batchInsert('{{%dic_navigation}}', ['name'], [
['Радар'],
['Радиосвязь'],
['Пожарная сигнализация и система пожаротушени'],
['Эхолот'],
['Помпа'],
['Команда тренированная по CPR'],
['Команда тренированная по оказанию первой помощи'],
['Ультразвуковой сонар'],
['Спасательные плоты'],
['Кислород'],
['Сирена'],
['Поисковый прожектор'],
['GPS'],
['Спасательные жилеты'],
['Аптечки первой помощи'],
['Спутниковая и сотовая связь'],
['Система видеонаблюдения в машинном отделении'],
['Аварийные факелы'],
]);
//food
$this->createTable('{{%dic_food}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
$this->createTable('{{%entity_boat_food_link}}', [
'entityId' => $this->integer()->notNull(),
'foodId' => $this->integer(),
], $tableOptions);
$this->addForeignKey('FK_entity_boat_food_entity', '{{%entity_boat_food_link}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_boat_food_food', '{{%entity_boat_food_link}}', 'foodId', '{{%dic_food}}', 'id', 'CASCADE', 'CASCADE');
$this->batchInsert('{{%dic_food}}', ['name'], [
['Западная кухня'],
['Местная кухня'],
['Вегетарианская кухня'],
['Шведский стол'],
['Пиво'],
['Вина'],
['Высокая кухня'],
['Горячие-холодные напитки'],
['Закуски в течение дня'],
['Мороженница']
]);
//service
$this->createTable('{{%dic_service}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
$this->createTable('{{%entity_boat_service_link}}', [
'entityId' => $this->integer()->notNull(),
'serviceId' => $this->integer(),
], $tableOptions);
$this->addForeignKey('FK_entity_boat_service_entity', '{{%entity_boat_service_link}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_boat_service_service', '{{%entity_boat_service_link}}', 'serviceId', '{{%dic_service}}', 'id', 'CASCADE', 'CASCADE');
$this->batchInsert('{{%dic_service}}', ['name'], [
['Подходит для детей'],
['Подходит для не-дайверов'],
['Кондиционирование салона'],
['Кондиционирование в каютах'],
['Двухместные кровати'],
['Салон на открытом воздухе'],
['Бар'],
['Сан дек'],
['Бассейн на сан деке'],
['Сауна'],
['Джакузи'],
['Библиотека'],
['ТВ в каютах'],
['Зарядные станции'],
['Компьютер'],
['Душ с теплой водой'],
['Массаж'],
['Ежедневная уборка'],
['Прачечная'],
['Просторный дайв-дек'],
['Каяки'],
['Специальное хранилище для фототехники'],
['Оборудована для фотографов']
]);
//diving
$this->createTable('{{%dic_diving}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
$this->createTable('{{%entity_boat_diving_link}}', [
'entityId' => $this->integer()->notNull(),
'divingId' => $this->integer(),
], $tableOptions);
$this->addForeignKey('FK_entity_boat_diving_entity', '{{%entity_boat_diving_link}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_boat_diving_diving', '{{%entity_boat_diving_link}}', 'divingId', '{{%dic_diving}}', 'id', 'CASCADE', 'CASCADE');
$this->batchInsert('{{%dic_diving}}', ['name'], [
['баллоны Yoke'],
['баллоны DIN'],
['Поддержка ребризеров'],
['Компрессоры'],
['Технический дайвинг'],
['Дайв-дек']
]);
$this->addColumn('{{%entity_boat}}', 'year', $this->integer());
$this->renameColumn('{{%entity_resort}}', 'openingTime', 'checkinTime');
$this->renameColumn('{{%entity_resort}}', 'nonDiver', 'activities');
}
public function down()
{
$this->renameTable('{{%dic_fleet}}', '{{%fleet}}');
$this->renameTable('{{%dic_material}}', '{{%material}}');
$this->dropTable('{{%entity_language_link}}');
$this->dropTable('{{%dic_language}}');
$this->dropTable('{{%entity_document_link}}');
$this->dropTable('{{%dic_document}}');
$this->dropTable('{{%entity_boat_navigation_link}}');
$this->dropTable('{{%dic_navigation}}');
$this->dropTable('{{%entity_boat_food_link}}');
$this->dropTable('{{%dic_food}}');
$this->dropTable('{{%entity_boat_service_link}}');
$this->dropTable('{{%dic_service}}');
$this->dropTable('{{%entity_boat_diving_link}}');
$this->dropTable('{{%dic_diving}}');
$this->dropColumn('{{%entity_boat}}', 'year');
$this->renameColumn('{{%entity_resort}}', 'checkinTime', 'openingTime');
$this->renameColumn('{{%entity_resort}}', 'activities', 'nonDiver');
}
}