<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation for table `service_lang`.
     */
    class m160930_133757_create_service_lang_table extends Migration
    {
        
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable('service_lang', [
                'service_id'  => $this->integer()
                                      ->notNull(),
                'language_id' => $this->integer()
                                      ->notNull(),
                'name'        => $this->string()
                                      ->notNull(),
                'body'        => $this->text()
                                      ->notNull(),
                'seo_text'    => $this->text(),
                'meta_title'  => $this->string(),
                'description' => $this->string(),
                'h1'          => $this->string(),
            ]);
            $this->createIndex('service_lang_service_language_key', 'service_lang', [
                'service_id',
                'language_id',
            ], true);
            
            $this->addForeignKey('service_fk', 'service_lang', 'service_id', 'service', 'service_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'service_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropTable('service_lang');
        }
    }
