m150901_141850_addImportersPrefix.php
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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()
    {
    }
    */
}