m150901_141850_addImportersPrefix.php 1.05 KB
<?php

use yii\db\Schema;
use yii\db\Migration;

class m150901_141850_addImportersPrefix extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%importer_prefix}}', [
            'id' => $this->primaryKey(10)->notNull() . ' AUTO_INCREMENT',
            'importer_id' => 'int(6) unsigned NOT NULL',
            'brand' => 'varchar(100) NOT NULL',
            'prefix' => 'varchar(50) NOT NULL',
            'timestamp' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
        ], $tableOptions);

        $this->createIndex('importer_id', '{{%importer_prefix}}', 'importer_id, brand, prefix', true);
    }

    public function down()
    {
        $this->dropTable('{{%importer_prefix}}');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}