<?php

use yii\db\Migration;

/**
 * Handles the creation of table `doctor_lang`.
 */
class m180531_111128_create_doctor_lang_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('doctor_lang', [
            'language_id' => $this->integer(),
            'alias_id'    => $this->integer(),
            'doctor_id'   => $this->integer(),
            'name'        => $this->string(),
            'position'    => $this->string(),
            'description' => $this->text()
        ]);
        
        $this->addPrimaryKey('doctor_lang_pk', 'doctor_lang', ['language_id', 'doctor_id']);
        
        $this->addForeignKey('doctor_lang_language_fk',
                            'doctor_lang',
                            'language_id',
                            'language',
                            'id');
        $this->addForeignKey('doctor_lang_doctor_fk',
                            'doctor_lang',
                            'doctor_id',
                            'doctor',
                            'id',
                            'CASCADE',
                            'CASCADE');
        
        $this->addForeignKey('doctor_lang_alias_fk',
                            'doctor_lang',
                            'alias_id',
                            'alias',
                            'id',
                            'CASCADE',
                            'CASCADE');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey('doctor_lang_language_fk', 'doctor_lang');
        $this->dropForeignKey('doctor_lang_doctor_fk', 'doctor_lang');
        $this->dropForeignKey('doctor_lang_alias_fk', 'doctor_lang');
        $this->dropTable('doctor_lang');
    }
}
