File: /home/safarimaris/home/safarimaris/console/migrations/m130524_201442_init.php
<?php
use yii\db\Migration;
class m130524_201442_init 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';
}
//user
$this->createTable('{{%user}}', [
'id' => $this->primaryKey(),
'username' => $this->string()->notNull()->unique(),
'auth_key' => $this->string(32)->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string()->unique(),
'email' => $this->string()->notNull()->unique(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull()
], $tableOptions);
//dictionary
//fleet
$this->createTable('{{%fleet}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
//material
$this->createTable('{{%material}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
//tag
$this->createTable('{{%tag}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()
], $tableOptions);
//country
$this->createTable('{{%country}}', [
'id' => $this->primaryKey(),
'ordinal' => $this->integer()->notNull(),
'name' => $this->string()->notNull(),
'url' => $this->string()->notNull(),
'logo' => $this->string()->notNull(),
'reason1' => $this->text(),
'reason2' => $this->text(),
'reason3' => $this->text(),
'reason4' => $this->text(),
'seasonLogo' => $this->string(),
'seasonText' => $this->text(),
'seo' => $this->text()
], $tableOptions);
//dive site
$this->createTable('{{%site}}', [
'id' => $this->primaryKey(),
'countryId' => $this->integer()->notNull(),
'name' => $this->string()->notNull(),
'url' => $this->string()->notNull(),
'description' => $this->text(),
'logo' => $this->string()
], $tableOptions);
$this->addForeignKey('FK_site_country', '{{%site}}', 'countryId', '{{%country}}', 'id', 'CASCADE', 'CASCADE');
//entity(boat or dive resort)
$this->createTable('{{%entity}}', [
'id' => $this->primaryKey(),
'countryId' => $this->integer()->notNull(),
'ordinal' => $this->integer()->notNull(),
'type' => $this->smallInteger(1)->notNull(),
'name' => $this->string()->notNull(),
'description' => $this->text(),
'logo' => $this->string(),
'seoUrl' => $this->string(),
'seoTitle' => $this->string(),
'seoDescription' => $this->string(),
], $tableOptions);
$this->addForeignKey('FK_entity_country', '{{%entity}}', 'countryId', '{{%country}}', 'id', 'CASCADE', 'CASCADE');
$this->createTable('{{%entity_boat}}', [
'id' => $this->primaryKey(),
'entityId' => $this->integer()->notNull(),
'fleetId' => $this->integer(),
'width' => $this->integer(4),
'length' => $this->integer(4),
'materialId' => $this->integer(),
'countCabin' => $this->integer(4),
'boatPlan' => $this->string(),
'compressor' => $this->string(),
'generator' => $this->string(),
'engine' => $this->string(),
'capacity' => $this->string(),
'tender' => $this->string(),
'socket' => $this->string(),
'techEquip' => $this->string(),
'disabilitiesEquip' => $this->string(),
'waterCapacity' => $this->string(),
'lastDockDate' => $this->date(),
'lastRenovationDate' => $this->date(),
'nitrox' => $this->integer(1),
'wifi' => $this->integer(1)
], $tableOptions);
$this->addForeignKey('FK_entity_boat', '{{%entity_boat}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_boat_fleet', '{{%entity_boat}}', 'fleetId', '{{%fleet}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_entity_boat_material', '{{%entity_boat}}', 'materialId', '{{%material}}', 'id', 'CASCADE', 'CASCADE');
$this->createTable('{{%entity_resort}}', [
'id' => $this->primaryKey(),
'entityId' => $this->integer()->notNull(),
'openingTime' => $this->string(),
'nonDiver' => $this->string(),
'nitrox' => $this->integer(1),
'techDiving' => $this->integer(1),
'countBoat' => $this->integer(),
'airportTransfer' => $this->integer(1),
'decompressDistance' => $this->integer(),
'hotelTransfer' => $this->integer(1)
], $tableOptions);
$this->addForeignKey('FK_entity_resort', '{{%entity_resort}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
//reviews
$this->createTable('{{%review}}', [
'id' => $this->primaryKey(),
'entityId' => $this->integer()->notNull(),
'userId' => $this->integer()->notNull(),
'title' => $this->string()->notNull(),
'text' => $this->text()->notNull(),
'date' => $this->dateTime()->notNull(),
'rating' => $this->float()->notNull(),
'ratingInfrastructure' => $this->integer()->notNull(),
'ratingGuiding' => $this->integer()->notNull(),
'ratingService' => $this->integer()->notNull(),
'ratingSealife' => $this->integer()->notNull()
], $tableOptions);
$this->addForeignKey('FK_review_entity', '{{%review}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_review_user', '{{%review}}', 'userId', '{{%user}}', 'id', 'CASCADE', 'CASCADE');
//special offers
$this->createTable('{{%special}}', [
'id' => $this->primaryKey(),
'entityId' => $this->integer()->notNull(),
'title' => $this->string()->notNull(),
'tag' => $this->string()->notNull(),
'entityTitle' => $this->string()->notNull(),
'descr' => $this->text()->notNull(),
'term' => $this->text()->notNull(),
'announceStart' => $this->date()->notNull(),
'announceEnd' => $this->date()->notNull(),
'isInstructor' => $this->integer(1),
'ordinal' => $this->integer()->notNull()
], $tableOptions);
$this->addForeignKey('FK_special_entity', '{{%special}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
//product
$this->createTable('{{%product}}', [
'id' => $this->primaryKey(),
'entityId' => $this->integer()->notNull(),
'name' => $this->string()->notNull(),
'descr' => $this->text(),
'include' => $this->text(),
'notInclude' => $this->text(),
'additionalCost' => $this->text(),
'itinerary' => $this->text(),
'departurePort' => $this->string(),
'arrivalPort' => $this->string(),
'transferType' => $this->integer(),
'transferFrom' => $this->string(),
'transferTo' => $this->string(),
'checkInOut' => $this->string(),
'countDive' => $this->integer(),
'minCertificate' => $this->integer(),
'minDive' => $this->integer()
], $tableOptions);
$this->addForeignKey('FK_product_entity', '{{%product}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->createTable('{{%product_tag}}', [
'productId' => $this->integer(),
'tagId' => $this->integer(),
'PRIMARY KEY(productId, tagId)',
]);
$this->addForeignKey('FK_product_tag_product', '{{%product_tag}}', 'productId', '{{%product}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_product_tag_tag', '{{%product_tag}}', 'tagId', '{{%tag}}', 'id', 'CASCADE', 'CASCADE');
$this->createTable('{{%product_site}}', [
'productId' => $this->integer(),
'siteId' => $this->integer(),
'PRIMARY KEY(productId, siteId)',
]);
$this->addForeignKey('FK_product_site_product', '{{%product_site}}', 'productId', '{{%product}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('FK_product_site_site', '{{%product_site}}', 'siteId', '{{%site}}', 'id', 'CASCADE', 'CASCADE');
//tour
$this->createTable('{{%tour}}', [
'id' => $this->primaryKey(),
'entityId' => $this->integer()->notNull(),
'startDate' => $this->date(),
'isOpenDate' => $this->integer(1),
'duration' => $this->integer()->notNull(),
'name' => $this->string()->notNull(),
'price' => $this->string()->notNull(),
'salePrice' => $this->string(),
'spaces' => $this->string()->notNull(),
'productId' => $this->string(),
'isSpecial' => $this->integer(1),
'isCompatriot' => $this->integer(1),
'notice' => $this->text()
], $tableOptions);
$this->addForeignKey('FK_tour_entity', '{{%tour}}', 'entityId', '{{%entity}}', 'id', 'CASCADE', 'CASCADE');
$this->createTable('{{%tour_open}}', [
'id' => $this->primaryKey(),
'productId' => $this->integer()->notNull(),
'm1' => $this->integer(),
'm2' => $this->integer(),
'm3' => $this->integer(),
'm4' => $this->integer(),
'm5' => $this->integer(),
'm6' => $this->integer(),
'm7' => $this->integer(),
'm8' => $this->integer(),
'm9' => $this->integer(),
'm10' => $this->integer(),
'm11' => $this->integer(),
'm12' => $this->integer(),
], $tableOptions);
$this->addForeignKey('FK_tour_open', '{{%tour_open}}', 'productId', '{{%product}}', 'id', 'CASCADE', 'CASCADE');
}
public function down()
{
$this->dropTable('{{%tour_open}}');
$this->dropTable('{{%tour}}');
$this->dropTable('{{%product_site}}');
$this->dropTable('{{%product_tag}}');
$this->dropTable('{{%product}}');
$this->dropTable('{{%special}}');
$this->dropTable('{{%review}}');
$this->dropTable('{{%entity_resort}}');
$this->dropTable('{{%entity_boat}}');
$this->dropTable('{{%entity}}');
$this->dropTable('{{%site}}');
$this->dropTable('{{%country}}');
$this->dropTable('{{%fleet}}');
$this->dropTable('{{%material}}');
$this->dropTable('{{%tag}}');
$this->dropTable('{{%user}}');
}
}