<?php
    
    use yii\db\Migration;
    
    class m170627_095533_slider_tables extends Migration
    {
        public function safeUp()
        {
            
            $this->createTable(
                'slide',
                [
                    'id'        => $this->primaryKey(),
                    'status'    => $this->boolean()
                                        ->defaultValue(true),
                    'sort'      => $this->integer()
                                        ->defaultValue(0),
                ]
            );
            
            
            $this->createTable(
                'slide_lang',
                [
                    'slide_id'    => $this->integer()
                                          ->notNull(),
                    'language_id' => $this->integer()
                                          ->notNull(),
                    'link'        => $this->string(),
                    'image_id'    => $this->integer(),
                    'title'       => $this->string(),
                ]
            );
            
            $this->addForeignKey(
                'slide_lang_slide_fkey',
                'slide_lang',
                'slide_id',
                'slide',
                'id',
                'CASCADE',
                'CASCADE'
            );
            $this->addForeignKey(
                'slide_lang_language_fkey',
                'slide_lang',
                'language_id',
                'language',
                'id',
                'CASCADE',
                'CASCADE'
            );
            $this->addForeignKey(
                'slide_lang_image_fkey',
                'slide_lang',
                'image_id',
                'ImageManager',
                'id',
                'CASCADE',
                'CASCADE'
            );
        }
        
        public function safeDown()
        {
            $this->dropForeignKey('slide_lang_slide_fkey', 'slide_lang');
            $this->dropForeignKey('slide_lang_language_fkey', 'slide_lang');
            $this->dropForeignKey('slide_lang_image_fkey', 'slide_lang');
            
            $this->dropTable('slide_lang');
            
            
            $this->dropTable('slide');
            
        }
    }
