m160930_100954_create_seo_lang_table.php 3.32 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(),
                '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', 'seo_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'seo_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
            $this->createTable('seo_category_lang', [
                'seo_category_id' => $this->integer()
                                          ->notNull(),
                'language_id'     => $this->integer()
                                          ->notNull(),
                'name'            => $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', 'seo_category_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'seo_category_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
            $this->createTable('seo_dynamic_lang', [
                'seo_dynamic_id' => $this->integer()
                                         ->notNull(),
                'language_id'    => $this->integer()
                                         ->notNull(),
                'name'           => $this->string(),
                'title'          => $this->text(),
                'h1'             => $this->string(),
                'key'            => $this->string(),
                'meta'           => $this->string(),
                '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', 'seo_dynamic_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'seo_dynamic_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropTable('seo_lang');
            $this->dropTable('seo_category_lang');
            $this->dropTable('seo_dynamic_lang');
        }
    }