<?php
    
    use yii\db\Migration;
    
    class m170309_000003_alias extends Migration
    {
        public function safeUp()
        {
            $this->createTable(
                'alias',
                [
                    'id'          => $this->primaryKey(),
                    'value'       => $this->string()
                                          ->notNull(),
                    'route'       => $this->string(),
                    'title'       => $this->string(),
                    'description' => $this->text(),
                    'h1'          => $this->string(),
                    'robots'      => $this->string(),
                    'seo_text'    => $this->text(),
                    'entity'      => $this->string(),
                    'fields'=> $this->text(),
                    'language_id'=>  $this->integer()
                ]
            );
    
            $this->addForeignKey('alias_to_language', 'alias', 'language_id', 'language', 'id', 'SET NULL', 'CASCADE');
    
            $this->createIndex(
                'alias_value_language_id_uix',
                'alias',
                [
                    'value',
                    'language_id',
                ],
                true
            );
        }
        
        public function safeDown()
        {
            $this->dropForeignKey('alias_to_language', 'alias');
            $this->dropIndex('alias_value_language_id_uix', 'alias');
            $this->dropTable('alias');
        }
    }
