m160705_103701_create_table_city.php
2.1 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
69
70
71
72
73
74
75
76
77
<?php
use yii\db\Migration;
use thread\modules\location\Location as ParentModule;
/**
* Class m160705_103701_create_table_city
*
* @author FilamentV <vortex.filament@gmail.com>
* @copyright (c), Thread
*/
class m160705_103701_create_table_city extends Migration
{
/**
* @var string
*/
public $table = '{{%location_city}}';
/**
* @var string
*/
public $tableCountry = '{{%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'),
'country_id' => $this->integer()->unsigned()->comment('country_id'),
'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');
$this->addForeignKey(
'fv_location_city_ibfk_1',
$this->table,
'country_id',
$this->tableCountry,
'id',
'CASCADE',
'CASCADE'
);
}
/**
* Cancel migration
*/
public function safeDown()
{
$this->dropForeignKey('fv_location_city_ibfk_1', $this->table);
$this->dropIndex('deleted', $this->table);
$this->dropIndex('published', $this->table);
$this->dropTable($this->table);
}
}