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

CreateEntityRelationshipsTable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 59 2
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
use Phinx\Db\Adapter\MysqlAdapter;
5
6
class CreateEntityRelationshipsTable extends AbstractMigration {
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("entity_relationships")) {
31
			return;
32
		}
33
34
		$table = $this->table("entity_relationships", [
35
			'engine' => "InnoDB",
36
			'encoding' => "utf8mb4",
37
			'collation' => "utf8mb4_general_ci",
38
		]);
39
40
		$table->addColumn('guid_one', 'integer', [
41
			'null' => false,
42
			'limit' => MysqlAdapter::INT_BIG,
43
			'precision' => 20,
44
			'signed' => false,
45
		]);
46
47
		$table->addColumn('relationship', 'string', [
48
			'null' => false,
49
			'limit' => 50,
50
		]);
51
52
		$table->addColumn('guid_two', 'integer', [
53
			'null' => false,
54
			'limit' => MysqlAdapter::INT_BIG,
55
			'precision' => 20,
56
			'signed' => false,
57
		]);
58
59
		$table->addColumn('time_created', 'integer', [
60
			'null' => false,
61
			'limit' => MysqlAdapter::INT_REGULAR,
62
			'precision' => 10,
63
		]);
64
65
		$table->addIndex([
66
			'guid_one',
67
			'relationship',
68
			'guid_two'
69
		], [
70
			'name' => "guid_one",
71
			'unique' => true,
72
		]);
73
74
		$table->addIndex(['relationship'], [
75
			'name' => "relationship",
76
			'unique' => false,
77
		]);
78
79
		$table->addIndex(['guid_two'], [
80
			'name' => "guid_two",
81
			'unique' => false
82
		]);
83
84
		$table->save();
85
86
	}
87
}
88