Completed
Push — master ( d8f0fb...9008ba )
by Anton
10s
created

ModuleOptions::change()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class ModuleOptions 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
        $table = $this->table('options', ['id' => false, 'primary_key' => ['namespace', 'key']]);
31
        $table
32
            ->addColumn('userId', 'integer')
33
            ->addColumn('namespace', 'string', ['length' => 255, 'default' => 'default'])
34
            ->addColumn('key', 'string', ['length' => 255])
35
            ->addColumn('value', 'text')
36
            ->addColumn('description', 'text', ['null' => true])
37
            ->addTimestamps('created', 'updated')
38
            ->addForeignKey('userId', 'users', 'id', [
39
                'delete' => 'CASCADE',
40
                'update' => 'CASCADE'
41
            ])
42
            ->create();
43
    }
44
}
45