Completed
Push — master ( 92ff78...57630a )
by Steve
20:35 queued 09:38
created

20170728074925_create_metadata_table.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
use Phinx\Db\Adapter\MysqlAdapter;
5
6 View Code Duplication
class CreateMetadataTable extends AbstractMigration {
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
	/**
8
	 * Change Method.
9
	 *
10
	 * Write your reversible migrations using this method.
11
	 *
12
	 * More information on writing migrations is available here:
13
	 * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
14
	 *
15
	 * The following commands can be used in this method and Phinx will
16
	 * automatically reverse them when rolling back:
17
	 *
18
	 *    createTable
19
	 *    renameTable
20
	 *    addColumn
21
	 *    renameColumn
22
	 *    addIndex
23
	 *    addForeignKey
24
	 *
25
	 * Remember to call "create()" or "update()" and NOT "save()" when working
26
	 * with the Table class.
27
	 */
28
	public function change() {
29
30
		if ($this->hasTable("metadata")) {
31
			return;
32
		}
33
34
		$table = $this->table("metadata", [
35
			'engine' => "InnoDB",
36
			'encoding' => "utf8mb4",
37
			'collation' => "utf8mb4_general_ci",
38
		]);
39
40
		$table->addColumn('entity_guid', 'integer', [
41
			'null' => false,
42
			'limit' => MysqlAdapter::INT_BIG,
43
			'precision' => 20,
44
			'signed' => false,
45
		]);
46
47
		$table->addColumn('name', 'text', [
48
			'null' => false,
49
			'limit' => 65535,
50
		]);
51
52
		$table->addColumn('value', 'text', [
53
			'null' => false,
54
			'limit' => MysqlAdapter::TEXT_LONG,
55
		]);
56
57
		$table->addColumn('value_type', 'enum', [
58
			'null' => false,
59
			'limit' => 7,
60
			'values' => [
61
				'integer',
62
				'text'
63
			],
64
		]);
65
66
		$table->addColumn('owner_guid', 'integer', [
67
			'null' => false,
68
			'limit' => MysqlAdapter::INT_BIG,
69
			'precision' => 20,
70
			'signed' => false,
71
		]);
72
73
		$table->addColumn('access_id', 'integer', [
74
			'null' => false,
75
			'limit' => MysqlAdapter::INT_REGULAR,
76
			'precision' => 10,
77
		]);
78
79
		$table->addColumn('time_created', 'integer', [
80
			'null' => false,
81
			'limit' => MysqlAdapter::INT_REGULAR,
82
			'precision' => 10,
83
		]);
84
85
		$table->addColumn('enabled', 'enum', [
86
			'null' => false,
87
			'default' => 'yes',
88
			'limit' => 3,
89
			'values' => [
90
				'yes',
91
				'no'
92
			],
93
		]);
94
		
95
		$table->addIndex(['entity_guid'], [
96
			'name' => "entity_guid",
97
			'unique' => false,
98
		]);
99
		
100
		$table->addIndex(['name'], [
101
			'name' => "name",
102
			'unique' => false,
103
			'limit' => 50,
104
		]);
105
		
106
		$table->addIndex(['value'], [
107
			'name' => "value",
108
			'unique' => false,
109
			'limit' => 50,
110
		]);
111
112
		$table->addIndex(['owner_guid'], [
113
			'name' => "owner_guid",
114
			'unique' => false,
115
		]);
116
		
117
		$table->addIndex(['access_id'], [
118
			'name' => "access_id",
119
			'unique' => false,
120
		]);
121
122
		$table->save();
123
124
	}
125
}
126