m161011_104931_create_stock_lang_table.php 1.04 KB
<?php

use yii\db\Migration;

/**
 * Handles the creation for table `stock_lang`.
 */
class m161011_104931_create_stock_lang_table extends Migration
{
    /**
     * @inheritdoc
     */
    public function up()
    {
        $this->createTable('stock_lang', [
            'stock_id' => $this->integer()
                                    ->notNull(),
            'language_id'  => $this->integer()
                                   ->notNull(),
            'name'         => $this->string()
                                    ->notNull(),
        ]);
        $this->createIndex('stock_lang_stock_language_key', 'stock_lang', [
            'stock_id',
            'language_id',
        ], true);
        
        $this->addForeignKey('stock_fk', 'stock_lang', 'stock_id', 'stock', 'stock_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('language_fk', 'stock_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
    }

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