-
Notifications
You must be signed in to change notification settings - Fork 503
/
20180507182549_create_hxl_tags_tables.php
73 lines (65 loc) · 2.45 KB
/
20180507182549_create_hxl_tags_tables.php
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
<?php
use Phinx\Migration\AbstractMigration;
class CreateHxlTagsTables extends AbstractMigration
{
public function up()
{
$this->table('hxl_tags')
->addColumn('tag_name', 'string', [
'null' => false,
'default' => false,
'comment' => 'The hxl tag. Examples: #geo, #population, #gender'
])
->addColumn('description', 'string', [
'null' => false,
'default' => false,
'comment' => 'The hxl tag description.'
])
->addIndex(['tag_name'], ['unique' => true])
->create();
$this->table('hxl_attributes')
->addColumn('attribute', 'string', [
'null' => false,
'default' => false,
'comment' => 'The hxl attribute. Examples: +f, +m, +adolescents'
])
->addColumn('description', 'string', [
'null' => false,
'default' => false
])
->addIndex(['attribute'], ['unique' => true])
->create();
$this->table('hxl_tag_attributes', ['id' => false, 'primary_key' => ['tag_id', 'attribute_id']])
->addColumn('tag_id', 'integer', [
'null' => false,
'default' => false
])
->addColumn('attribute_id', 'integer', [
'null' => false,
'default' => false
])
->addIndex(['attribute_id', 'tag_id'], ['unique' => true])
->addForeignKey('attribute_id', 'hxl_attributes', 'id')
->addForeignKey('tag_id', 'hxl_tags', 'id')
->create();
$this->table('hxl_attribute_type_tag')
->addColumn('form_attribute_type', 'string', [
'null' => false,
'default' => false,
'comment' => 'The form attribute type. Examples: decimal, int, geometry, text, varchar, point'
])
->addColumn('hxl_tag_id', 'integer', [
'null' => false,
'default' => false
])
->addForeignKey('hxl_tag_id', 'hxl_tags', 'id')
->create();
}
public function down()
{
$this->table('hxl_tag_attributes')->drop()->save();
$this->table('hxl_attribute_type_tag')->drop()->save();
$this->table('hxl_attributes')->drop()->save();
$this->table('hxl_tags')->drop()->save();
}
}