<?php

use yii\db\Migration;

/**
 * Handles the creation of table `gallery_lang`.
 */
class m180507_120119_create_gallery_lang_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('gallery_lang', [
                'gallery_id' => $this->integer()
                                      ->notNull(),
                'language_id' => $this->integer()
                                      ->notNull(),
                'title'       => $this->string(),
                'PRIMARY KEY(gallery_id, language_id)',
        ]);
    
        
    
        $this->addForeignKey(
            'gallery_lang_fk',
            'gallery_lang',
            'language_id',
            'language',
            'id',
            'RESTRICT',
            'CASCADE'
        );
    
        $this->addForeignKey(
            'gallery_fk',
            'gallery_lang',
            'gallery_id',
            'gallery',
            'id',
            'CASCADE',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey('gallery_lang_fk', 'gallery_lang');
        $this->dropForeignKey('gallery_fk', 'gallery_lang');
        $this->dropTable('gallery_lang');
    }
}
