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

CreateAccessCollectionsTable::change()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 21
nc 2
nop 0
dl 0
loc 34
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
use Phinx\Db\Adapter\MysqlAdapter;
5
6
class CreateAccessCollectionsTable 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("access_collections")) {
31
			return;
32
		}
33
34
		$table = $this->table("access_collections", [
35
			'engine' => "InnoDB",
36
			'encoding' => "utf8mb4",
37
			'collation' => "utf8mb4_general_ci",
38
		]);
39
40
		$table->addColumn('name', 'text', [
41
			'null' => false,
42
			'limit' => 65535,
43
		]);
44
45
		$table->addColumn('owner_guid', 'integer', [
46
			'null' => false,
47
			'limit' => MysqlAdapter::INT_BIG,
48
			'precision' => 20,
49
			'signed' => false,
50
		]);
51
52
		$table->addIndex(['owner_guid'], [
53
			'name' => "owner_guid",
54
			'unique' => false
55
		]);
56
57
		$table->save();
58
59
		$prefix = $this->getAdapter()->getOption('table_prefix');
60
		$this->query("ALTER TABLE {$prefix}access_collections AUTO_INCREMENT=3");
61
	}
62
}
63