<?php

use yii\db\Migration;

/**
 * Handles the creation for table `product_lang`.
 */
class m160929_144357_create_product_lang_table extends Migration
{
    /**
     * @inheritdoc
     */
    public function up()
    {
        $this->createTable('product_lang', [
            'product_id'      => $this->integer()
                                       ->notNull(),
            'language_id'      => $this->integer()
                                       ->notNull(),
            'name'            => $this->string()
                                       ->notNull(),
            'description'             => $this->text(),
        ]);
        $this->createIndex('product_lang_product_language_key', 'product_lang', [
            'product_id',
            'language_id',
        ], true);
    
        $this->addForeignKey('product_fk', 'product_lang', 'product_id', 'product', 'product_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('language_fk', 'product_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
    }

    /**
     * @inheritdoc
     */
    public function down()
    {
        $this->dropTable('product_lang');
    }
}
