m160712_130834_create_road_surface.php
2.78 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
<?php
use yii\db\Migration;
/**
* Handles the creation for table `road_surface`.
*/
class m160712_130834_create_road_surface extends Migration
{
/**
* @inheritdoc
*/
public function up()
{
$this->createTable('road_surface', [
'road_surface_id' => $this->primaryKey()->comment('Індекс'),
'road_id' => $this->integer()->comment('Дорога'),
'region_id' => $this->integer()->comment('Область'),
'road_direction_id' => $this->integer()->comment('Напрямок смуги руху'),
'begin' => $this->float()->comment('Місцезнаходження, км+ початок'),
'end' => $this->float()->comment('Місцезнаходження, км+ кінець'),
'surface_type_id' => $this->integer()->comment('Тип покриття'),
'surface_treatment_id' => $this->integer()->comment('Тип поверхневої обробки'),
'state_common_id' => $this->integer()->comment('Стан покриття'),
]);
$this->createTable('surface_treatment', [
'surface_treatment_id' => $this->primaryKey(),
'name' => $this->string(),
]);
$this->batchInsert('surface_treatment', [ 'name' ], [
[ 'нема' ],
]);
$this->addForeignKey('road_surface_road_direction', 'road_surface', 'road_direction_id', 'road_direction', 'road_direction_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('road_surface_region', 'road_surface', 'region_id', 'region', 'region_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('road_surface_road', 'road_surface', 'road_id', 'road', 'road_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('road_surface_surface_type', 'road_surface', 'surface_type_id', 'surface_type', 'surface_type_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('road_surface_state_common', 'road_surface', 'state_common_id', 'state_common', 'state_common_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('road_surface_surface_treatment', 'road_surface', 'surface_treatment_id', 'surface_treatment', 'surface_treatment_id', 'CASCADE', 'CASCADE');
}
/**
* @inheritdoc
*/
public function down()
{
$this->dropForeignKey('road_surface_road_direction', 'road_surface');
$this->dropForeignKey('road_surface_region', 'road_surface');
$this->dropForeignKey('road_surface_road', 'road_surface');
$this->dropForeignKey('road_surface_surface_type', 'road_surface');
$this->dropForeignKey('road_surface_state_common', 'road_surface');
$this->dropForeignKey('road_surface_surface_treatment', 'road_surface');
$this->dropTable('road_surface');
$this->dropTable('surface_treatment');
}
}