m160930_100954_create_seo_lang_table.php 4.33 KB
<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation for table `seo_lang`.
     */
    class m160930_100954_create_seo_lang_table extends Migration
    {
        
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable(
                'seo_lang',
                [
                    'seo_id'           => $this->integer()
                                               ->notNull(),
                    'language_id'      => $this->integer()
                                               ->notNull(),
                    'title'            => $this->string(),
                    'meta_description' => $this->text(),
                    'h1'               => $this->string(),
                    'meta'             => $this->string(),
                    'seo_text'         => $this->text(),
                ]
            );
            $this->createIndex(
                'seo_lang_seo_language_key',
                'seo_lang',
                [
                    'seo_id',
                    'language_id',
                ],
                true
            );
            
            $this->addForeignKey('seo_fk', 'seo_lang', 'seo_id', 'seo', 'id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'seo_lang', 'language_id', 'language', 'id', 'RESTRICT', 'CASCADE');
            $this->createTable(
                'seo_category_lang',
                [
                    'seo_category_id' => $this->integer()
                                              ->notNull(),
                    'language_id'     => $this->integer()
                                              ->notNull(),
                    'title'           => $this->string(),
                ]
            );
            $this->createIndex(
                'seo_category_lang_seo_category_language_key',
                'seo_category_lang',
                [
                    'seo_category_id',
                    'language_id',
                ],
                true
            );
            
            $this->addForeignKey(
                'seo_category_fk',
                'seo_category_lang',
                'seo_category_id',
                'seo_category',
                'id',
                'CASCADE',
                'CASCADE'
            );
            $this->addForeignKey(
                'language_fk',
                'seo_category_lang',
                'language_id',
                'language',
                'id',
                'RESTRICT',
                'CASCADE'
            );
            $this->createTable(
                'seo_dynamic_lang',
                [
                    'seo_dynamic_id'   => $this->integer()
                                               ->notNull(),
                    'language_id'      => $this->integer()
                                               ->notNull(),
                    'title'            => $this->string(),
                    'meta_title'       => $this->text(),
                    'h1'               => $this->string(),
                    'key'              => $this->string(),
                    'meta'             => $this->string(),
                    'meta_description' => $this->text(),
                    'seo_text'         => $this->text(),
                ]
            );
            $this->createIndex(
                'seo_dynamic_lang_seo_dynamic_language_key',
                'seo_dynamic_lang',
                [
                    'seo_dynamic_id',
                    'language_id',
                ],
                true
            );
            
            $this->addForeignKey(
                'seo_dynamic_fk',
                'seo_dynamic_lang',
                'seo_dynamic_id',
                'seo_dynamic',
                'id',
                'CASCADE',
                'CASCADE'
            );
            $this->addForeignKey(
                'language_fk',
                'seo_dynamic_lang',
                'language_id',
                'language',
                'id',
                'RESTRICT',
                'CASCADE'
            );
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropTable('seo_lang');
            $this->dropTable('seo_category_lang');
            $this->dropTable('seo_dynamic_lang');
        }
    }