CreateMediaPropertiesTable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
dl 0
loc 35
rs 10
c 1
b 1
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 22 2
1
<?php
2
3
declare(strict_types=1);
4
5
use Phinx\Migration\AbstractMigration;
6
7
/**
8
 * Class OrgReportsFileStatus
9
 */
10
final class CreateMediaPropertiesTable extends AbstractMigration
11
{
12
    /**
13
     * Change Method.
14
     *
15
     * Write your reversible migrations using this method.
16
     *
17
     * More information on writing migrations is available here:
18
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
19
     *
20
     * Remember to call "create()" or "update()" and NOT "save()" when working
21
     * with the Table class.
22
     */
23
    public function change(): void
24
    {
25
        $table = $this->table('media-properties');
26
        if ($table->exists()) {
27
            return;
28
        }
29
30
        $table->addColumn('model', 'string');
31
        $table->addColumn('model_id', 'biginteger');
32
        $table->addColumn('collection_name', 'string');
33
34
        $table->addColumn('custom_properties', 'json');
35
36
        $table->addIndex(['model']);
37
        $table->addIndex(['model_id']);
38
        $table->addIndex(['collection_name']);
39
        $table->addIndex(['model', 'model_id', 'collection_name'], ['unique' => true]);
40
41
        $table->save();
42
43
        $table->changeColumn('id', 'biginteger', ['identity' => true]);
44
        $table->save();
45
    }
46
}
47