Completed
Push — master ( 9c5095...c059b6 )
by Anton
02:43
created

CreateOptionsTable::change()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class CreateOptionsTable extends AbstractMigration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
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
        $pages = $this->table('options', ['id' => false, 'primary_key' => ['namespace', 'key']]);
31
        $pages
32
            ->addColumn('namespace', 'string', ['length' => 255, 'default' => 'default'])
33
            ->addColumn('key', 'string', ['length' => 255])
34
            ->addColumn('description', 'text')
35
            ->addTimestamps('created', 'updated')
36
            ->create();
37
38
        $data = [
39
            [
40
                'roleId' => 2,
41
                'module' => 'options',
42
                'privilege' => 'Management'
43
            ]
44
        ];
45
46
        $privileges = $this->table('acl_privileges');
47
        $privileges->insert($data)
48
            ->save();
49
    }
50
}
51