m170309_000002_language.php 2.43 KB
<?php
    
    use yii\db\Migration;
    
    class m170309_000002_language extends Migration
    {
        public function safeUp()
        {
            $this->createTable(
                'language',
                [
                    'id'         => $this->primaryKey(),
                    'url'        => $this->string(255)
                                         ->notNull(),
                    'local'      => $this->string(255)
                                         ->notNull(),
                    'name'       => $this->string(255)
                                         ->notNull(),
                    'default'    => $this->boolean()
                                         ->notNull()
                                         ->defaultValue(false),
                    'created_at' => $this->integer(32)
                                         ->notNull(),
                    'updated_at' => $this->integer(32)
                                         ->notNull(),
                    'status'     => $this->boolean()
                                         ->notNull()
                                         ->defaultValue(false),
                ]
            );
            
            $this->batchInsert(
                'language',
                [
                    'url',
                    'local',
                    'name',
                    'default',
                    'created_at',
                    'updated_at',
                    'status',
                ],
                [
                    [
                        'en',
                        'en-EN',
                        'English',
                        true,
                        0,
                        0,
                        true,
                    ],
                    [
                        'ru',
                        'ru-RU',
                        'Русский',
                        false,
                        0,
                        0,
                        true,
                    ],
                    [
                        'ua',
                        'ua-UA',
                        'Українська',
                        false,
                        0,
                        0,
                        false,
                    ],
                ]
            );
        }
        
        public function safeDown()
        {
            $this->dropTable('language');
        }
    }