m160705_094012_create_table_country.php 1.87 KB
<?php

use yii\db\Migration;
use thread\modules\location\Location as ParentModule;

/**
 * Class m160705_094012_create_table_country
 *
 * @author FilamentV <vortex.filament@gmail.com>
 * @copyright (c), Thread
 */
class m160705_094012_create_table_country extends Migration
{
    /**
     * @var string
     */
    public $table = '{{%location_country}}';

    /**
     *
     */
    public function init()
    {
        $this->db = ParentModule::getDb();
        parent::init();
    }

    /**
     * Implement migration
     */
    public function safeUp()
    {
        $this->createTable($this->table, [
            'id' => $this->primaryKey()->unsigned()->comment('ID'),
            'alias' => $this->string(128)->notNull()->unique()->comment('alias'),
            'default_title' => $this->string(255)->defaultValue('')->comment('Default title'),
            'alpha2' => $this->string(2)->defaultValue('')->comment('alpha2'),
            'alpha3' => $this->string(3)->defaultValue('')->comment('alpha3'),
            'iso' => $this->string(3)->defaultValue('')->comment('iso'),
            'created_at' => $this->integer()->unsigned()->notNull()->defaultValue(0)->comment('Create time'),
            'updated_at' => $this->integer()->unsigned()->notNull()->defaultValue(0)->comment('Update time'),
            'published' => "enum('0','1') NOT NULL DEFAULT '0' COMMENT 'Published'",
            'deleted' => "enum('0','1') NOT NULL DEFAULT '0' COMMENT 'deleted'"
        ]);

        $this->createIndex('published', $this->table, 'published');
        $this->createIndex('deleted', $this->table, 'deleted');
    }

    /**
     * Cancel migration
     */
    public function safeDown()
    {
        $this->dropIndex('deleted', $this->table);
        $this->dropIndex('published', $this->table);
        //
        $this->dropIndex('alias', $this->table);
        $this->dropTable($this->table);
    }
}