m180530_131113_create_ImageManagerLant_table.php 1.27 KB
<?php

use yii\db\Migration;

/**
 * Handles the creation of table `ImageManagerLant`.
 */
class m180530_131113_create_ImageManagerLant_table extends Migration
{
    public function up()
    {
        $this->createTable(
            'ImageManagerLang',
            [
                'image_id'    => $this->integer(),
                'language_id' => $this->integer(),
                'title'       => $this->string(),
                'alt'         => $this->string(),
                'description' => $this->string(),
            ]
        );

        $this->addForeignKey(
            'image_fk',
            'ImageManagerLang',
            'image_id',
            'ImageManager',
            'id',
            'CASCADE',
            'CASCADE'
        );

        $this->addForeignKey(
            'language_fk',
            'ImageManagerLang',
            'language_id',
            'language',
            'id',
            'CASCADE',
            'CASCADE'
        );

        $this->createIndex(
            'img_lang_uk',
            'ImageManagerLang',
            [
                'language_id',
                'image_id',
            ],
            true
        );
    }

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