m160712_110146_create_cross_section.php
4.79 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
78
79
80
81
82
83
84
85
86
87
<?php
use yii\db\Migration;
/**
* Handles the creation for table `cross_section`.
*/
class m160712_110146_create_cross_section extends Migration
{
/**
* @inheritdoc
*/
public function up()
{
$this->createTable('cross_section', [
'cross_section_id' => $this->primaryKey()
->comment('Індекс'),
'region_id' => $this->integer()
->comment('Область'),
'road_id' => $this->integer()
->comment('Дорога'),
'location_left' => $this->float()
->comment('Місцеположення, км+ справа'),
'location_right' => $this->float()
->comment('Місцеположення, км+ зліва'),
'direction' => $this->string()
->comment('Напрямок з\'їзду'),
'surface_type_id' => $this->integer()
->comment('Тип покриття'),
'length_section' => $this->float()
->comment('Фактична довжина, м з\'їзду'),
'length_surface' => $this->float()
->comment('Фактична довжина, м покриття'),
'distance_edge' => $this->float()
->comment('Відстань від крайки проїзної частики, м'),
'width' => $this->float()
->comment('Ширина, м'),
'angle' => $this->float()
->comment('Кут примикання'),
'tube_availability' => $this->integer()
->comment('Наявність облаштування, труба'),
'safety_availability' => $this->integer()
->comment('Наявність облаштування, острівок безпеки'),
'year_build' => $this->integer()
->comment('Рік спорудження'),
'year_repair' => $this->integer()
->comment('Рік ремонту'),
'state_common_id' => $this->integer()
->comment('Технічний стан'),
]);
$this->createTable('surface_type', [
'surface_type_id' => $this->primaryKey(),
'name' => $this->string(),
]);
$this->createTable('state_common', [
'state_common_id' => $this->primaryKey()->comment('Ідентифікатор'),
'value' => $this->string()->comment('Значення'),
]);
$this->addCommentOnTable('state_common', 'Стан простого об’єкту');
$this->batchInsert('state_common', [ 'value' ], [
[ 'добрий' ],
[ 'задовільний' ],
[ 'незадовільний' ],
[ 'непрацездатний' ],
[ 'аварійний' ],
]);
$this->addForeignKey('cross_section_region', 'cross_section', 'region_id', 'region', 'region_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('cross_section_road', 'cross_section', 'road_id', 'road', 'road_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('cross_section_surface_type', 'cross_section', 'surface_type_id', 'surface_type', 'surface_type_id', 'CASCADE', 'CASCADE');
$this->addForeignKey('cross_section_state_common', 'cross_section', 'state_common_id', 'state_common', 'state_common_id', 'CASCADE', 'CASCADE');
}
/**
* @inheritdoc
*/
public function down()
{
$this->dropForeignKey('cross_section_region', 'cross_section');
$this->dropForeignKey('cross_section_road', 'cross_section');
$this->dropForeignKey('cross_section_surface_type', 'cross_section');
$this->dropForeignKey('cross_section_state_common', 'cross_section');
$this->dropTable('cross_section');
$this->dropTable('surface_type');
$this->dropTable('state_common');
}
}