m150915_125129_addDetails.php
2.22 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
use yii\db\Schema;
use yii\db\Migration;
class m150915_125129_addDetails extends Migration
{
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%details}}', [
'ID' => 'int(10) UNSIGNED NOT NULL',
'IMPORT_ID' => 'int(6) unsigned NOT NULL',
'BRAND' => 'varchar(100) NOT NULL',
'ARTICLE' => 'varchar(100) NOT NULL',
'FULL_ARTICLE' => 'varchar(150) NOT NULL',
'PRICE' => 'float(15,2) unsigned NOT NULL',
'DESCR' => 'varchar(200) NOT NULL',
'BOX' => 'int(6) unsigned NOT NULL',
'ADD_BOX' => 'int(6) unsigned NOT NULL DEFAULT 0',
'GROUP' => 'varchar(200) NOT NULL',
'timestamp' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',], $tableOptions);
//$this->dropPrimaryKey('ID','{{%details}}');
$this->createIndex('ID_delete', '{{%details}}', 'ID', true);
$this->execute('ALTER TABLE details
CHANGE COLUMN ID ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT');
$this->addPrimaryKey('importer_id', '{{%details}}', 'import_id, brand, ARTICLE');
$this->createIndex('timestamp', '{{%details}}', 'timestamp', false);
$this->createIndex('ARTICLE', '{{%details}}', 'ARTICLE', 'BRAND', 'ADD_BOX', false);
$this->createIndex('IMPORT_ID', '{{%details}}', 'ARTICLE', false);
$this->createIndex('IMPORT_ID_2', '{{%details}}', 'IMPORT_ID', 'timestamp', false);
// PRIMARY KEY ('ARTICLE','BRAND','IMPORT_ID'),
// UNIQUE KEY 'ID_delete' ('ID'),
// KEY 'timestamp' ('timestamp'),
// KEY 'ARTICLE' ('ARTICLE','BRAND','BOX'),
// KEY 'BRAND' ('BRAND','ARTICLE'),
// KEY 'ARTICLE_2' ('ARTICLE','BRAND','ADD_BOX'),
// KEY 'IMPORT_ID' ('IMPORT_ID','ARTICLE'),
// KEY 'IMPORT_ID_2' ('IMPORT_ID','timestamp
}
public function down()
{
$this->dropTable('{{%details}}');
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}