Passed
Pull Request — master (#1883)
by Janko
55:13 queued 27:46
created

Version20240816121145_DatabaseEntry::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10
c 1
b 1
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Migrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
final class Version20240816121145_DatabaseEntry extends AbstractMigration
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Add database entry foreign keys and indices';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        $this->addSql('ALTER TABLE stu_ships ALTER database_id DROP NOT NULL');
20
        $this->addSql('UPDATE stu_ships SET database_id = null WHERE database_id = 0');
21
        $this->addSql('ALTER TABLE stu_colonies ADD CONSTRAINT FK_D1C60F73F0AA09DB FOREIGN KEY (database_id) REFERENCES stu_database_entrys (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
22
        $this->addSql('CREATE UNIQUE INDEX UNIQ_D1C60F73F0AA09DB ON stu_colonies (database_id)');
23
        $this->addSql('ALTER TABLE stu_ships ADD CONSTRAINT FK_A560DD56F0AA09DB FOREIGN KEY (database_id) REFERENCES stu_database_entrys (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
24
        $this->addSql('CREATE UNIQUE INDEX UNIQ_A560DD56F0AA09DB ON stu_ships (database_id)');
25
    }
26
27
    public function down(Schema $schema): void
28
    {
29
        $this->addSql('ALTER TABLE stu_ships DROP CONSTRAINT FK_A560DD56F0AA09DB');
30
        $this->addSql('DROP INDEX UNIQ_A560DD56F0AA09DB');
31
        $this->addSql('ALTER TABLE stu_colonies DROP CONSTRAINT FK_D1C60F73F0AA09DB');
32
        $this->addSql('DROP INDEX UNIQ_D1C60F73F0AA09DB');
33
    }
34
}
35