Completed
Push — master ( 19732d...076741 )
by Paweł
11:47
created

Version20170217123721   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 38.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 23
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 27 1
A down() 23 23 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace SWP\Migrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
8
/**
9
 * Auto-generated Migration: Please modify to your needs!
10
 */
11
class Version20170217123721 extends AbstractMigration
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\DBAL\Migrations\AbstractMigration has been deprecated with message: Please use Doctrine\Migrations\AbstractMigration

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
12
{
13
    /**
14
     * @param Schema $schema
15
     */
16
    public function up(Schema $schema)
17
    {
18
        // this up() migration is auto-generated, please modify it to your needs
19
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
20
21
        $this->addSql('CREATE SEQUENCE swp_revision_log_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
22
        $this->addSql('CREATE SEQUENCE swp_revision_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
23
        $this->addSql('CREATE TABLE swp_revision_log (id INT NOT NULL, target_revision_id INT DEFAULT NULL, source_revision_id INT DEFAULT NULL, object_type VARCHAR(255) NOT NULL, object_id INT NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, event VARCHAR(255) NOT NULL, tenant_code VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
24
        $this->addSql('CREATE INDEX IDX_A1F96AFD9AC03385 ON swp_revision_log (target_revision_id)');
25
        $this->addSql('CREATE INDEX IDX_A1F96AFD21852C2F ON swp_revision_log (source_revision_id)');
26
        $this->addSql('CREATE TABLE swp_revision (id INT NOT NULL, previous_revision_id INT DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, published_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, is_active BOOLEAN NOT NULL, unique_key VARCHAR(255) NOT NULL, status VARCHAR(255) NOT NULL, tenant_code VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
27
        $this->addSql('CREATE UNIQUE INDEX UNIQ_ACFB1381AF3077E5 ON swp_revision (previous_revision_id)');
28
        $this->addSql('ALTER TABLE swp_revision_log ADD CONSTRAINT FK_A1F96AFD9AC03385 FOREIGN KEY (target_revision_id) REFERENCES swp_revision (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
29
        $this->addSql('ALTER TABLE swp_revision_log ADD CONSTRAINT FK_A1F96AFD21852C2F FOREIGN KEY (source_revision_id) REFERENCES swp_revision (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
30
        $this->addSql('ALTER TABLE swp_revision ADD CONSTRAINT FK_ACFB1381AF3077E5 FOREIGN KEY (previous_revision_id) REFERENCES swp_revision (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
31
        $this->addSql('ALTER TABLE swp_article ALTER keywords DROP NOT NULL');
32
        $this->addSql('DROP INDEX swp_name_idx');
33
        $this->addSql('ALTER TABLE swp_container ADD revision_id INT DEFAULT NULL');
34
        $this->addSql('ALTER TABLE swp_container ADD uuid VARCHAR(255) NOT NULL DEFAULT substr(md5(random()::text), 0, 12);');
35
        $this->addSql('ALTER TABLE swp_container DROP width');
36
        $this->addSql('ALTER TABLE swp_container DROP height');
37
        $this->addSql('ALTER TABLE swp_container ALTER created_at SET DEFAULT \'now\'');
38
        $this->addSql('ALTER TABLE swp_container ADD CONSTRAINT FK_CF0E49301DFA7C8F FOREIGN KEY (revision_id) REFERENCES swp_revision (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
39
        $this->addSql('CREATE INDEX IDX_CF0E49301DFA7C8F ON swp_container (revision_id)');
40
        $this->addSql('CREATE UNIQUE INDEX swp_name_idx ON swp_container (name, tenant_code, revision_id)');
41
        $this->addSql('ALTER TABLE swp_widget ALTER created_at SET DEFAULT \'now\'');
42
    }
43
44
    /**
45
     * @param Schema $schema
46
     */
47 View Code Duplication
    public function down(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        // this down() migration is auto-generated, please modify it to your needs
50
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
51
52
        $this->addSql('ALTER TABLE swp_revision_log DROP CONSTRAINT FK_A1F96AFD9AC03385');
53
        $this->addSql('ALTER TABLE swp_revision_log DROP CONSTRAINT FK_A1F96AFD21852C2F');
54
        $this->addSql('ALTER TABLE swp_container DROP CONSTRAINT FK_CF0E49301DFA7C8F');
55
        $this->addSql('ALTER TABLE swp_revision DROP CONSTRAINT FK_ACFB1381AF3077E5');
56
        $this->addSql('DROP SEQUENCE swp_revision_log_id_seq CASCADE');
57
        $this->addSql('DROP SEQUENCE swp_revision_id_seq CASCADE');
58
        $this->addSql('DROP TABLE swp_revision_log');
59
        $this->addSql('DROP TABLE swp_revision');
60
        $this->addSql('ALTER TABLE swp_widget ALTER created_at SET DEFAULT \'2017-01-26 14:48:07.617947\'');
61
        $this->addSql('DROP INDEX IDX_CF0E49301DFA7C8F');
62
        $this->addSql('DROP INDEX swp_name_idx');
63
        $this->addSql('ALTER TABLE swp_container ADD height INT DEFAULT NULL');
64
        $this->addSql('ALTER TABLE swp_container DROP uuid');
65
        $this->addSql('ALTER TABLE swp_container ALTER created_at SET DEFAULT \'2017-01-26 14:48:07.617947\'');
66
        $this->addSql('ALTER TABLE swp_container RENAME COLUMN revision_id TO width');
67
        $this->addSql('CREATE UNIQUE INDEX swp_name_idx ON swp_container (name, tenant_code)');
68
        $this->addSql('ALTER TABLE swp_article ALTER keywords SET NOT NULL');
69
    }
70
}
71