<?php

use yii\db\Migration;

/**
 * Handles the creation of table `service_lang`.
 */
class m180522_094432_create_service_lang_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('service_lang',
            [
                'service_id'=> $this->integer(32)->notNull(),
                'language_id'=> $this->integer(32)->notNull(),
                'title'=> $this->string(255)->notNull(),
                'body'=> $this->text()->notNull(),
                'alias_id'=> $this->integer(),
                'PRIMARY KEY(service_id, language_id)',
            ]
        );
        
        $this->addForeignKey('service_lang_service_fk',
                             'service_lang',
                            'service_id',
                            'service',
                            'id',
                            'CASCADE',
                            'CASCADE');
        $this->addForeignKey('service_lang_language_fk',
                            'service_lang',
                            'language_id',
                            'language',
                            'id',
                            'CASCADE',
                            'CASCADE');
        $this->addForeignKey('service_lang_alias_fk',
                                'service_lang',
                            'alias_id',
                            'alias',
                            'id',
                            'SET NULL',
                            'CASCADE');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey('service_lang_service_fk', 'service_lang');
        $this->dropForeignKey('service_lang_language_fk', 'service_lang');
        $this->dropForeignKey('service_lang_alias_fk', 'service_lang');
        $this->dropTable('service_lang');
    }
}
