CreateMediaTable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 25 2
1
<?php
2
3
declare(strict_types=1);
4
5
use Phinx\Migration\AbstractMigration;
6
7
/**
8
 * Class OrgReportsFileStatus
9
 */
10
final class CreateMediaTable 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-records');
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('file_name', 'string');
35
        $table->addColumn('path', 'string');
36
        $table->addColumn('disk', 'string');
37
38
        $table->addIndex(['model']);
39
        $table->addIndex(['model_id']);
40
        $table->addIndex(['collection_name']);
41
42
        $table->addIndex(['model', 'model_id', 'collection_name', 'path'], ['unique' => true]);
43
44
        $table->save();
45
46
        $table->changeColumn('id', 'biginteger', ['identity' => true]);
47
        $table->save();
48
    }
49
}
50