<?php

use yii\db\Migration;

/**
 * Handles the creation of table `package_lang`.
 */
class m180525_141010_create_package_lang_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('package_lang', [
            'package_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(package_id, language_id)',
        ]);
    
        $this->addForeignKey('package_lang_package_fk',
                             'package_lang',
                             'package_id',
                             'package',
                             'id',
                             'CASCADE',
                             'CASCADE');
        $this->addForeignKey('package_lang_language_fk',
                             'package_lang',
                             'language_id',
                             'language',
                             'id',
                             'CASCADE',
                             'CASCADE');
        $this->addForeignKey('package_lang_alias_fk',
                             'package_lang',
                             'alias_id',
                             'alias',
                             'id',
                             'SET NULL',
                             'CASCADE');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey('package_lang_package_fk', 'package_lang');
        $this->dropForeignKey('package_lang_language_fk', 'package_lang');
        $this->dropForeignKey('package_lang_alias_fk', 'package_lang');
        $this->dropTable('package_lang');
    }
}
