CreateMediaTable::change()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 0
dl 0
loc 25
rs 9.7333
c 0
b 0
f 0
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