up()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 7

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 27
loc 27
rs 8.8571
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
10
namespace AnimeDb\Bundle\CatalogBundle\DoctrineMigrations;
11
12
use Doctrine\DBAL\Migrations\AbstractMigration;
13
use Doctrine\DBAL\Schema\Schema;
14
15
/**
16
 * Auto-generated Migration: Please modify to your needs!
17
 */
18 View Code Duplication
class Version20140117113408_StorageDescriptionIsNotRequired extends AbstractMigration
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    public function up(Schema $schema)
21
    {
22
        // create temp table from new structure
23
        $this->addSql('CREATE TABLE "_new" (
24
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
25
            name VARCHAR(128) NOT NULL,
26
            description TEXT DEFAULT NULL,
27
            type VARCHAR(16) NOT NULL,
28
            path TEXT DEFAULT NULL,
29
            modified DATE DEFAULT NULL
30
        )');
31
32
        $this->addSql('
33
            INSERT INTO
34
                "_new"
35
            SELECT
36
                id, name, description, type, path, modified
37
            FROM
38
                "storage"
39
        ');
40
        // rename new to origin and drop origin
41
        $this->addSql('ALTER TABLE storage RENAME TO _origin');
42
        $this->addSql('ALTER TABLE _new RENAME TO storage');
43
        $this->addSql('DROP TABLE _origin');
44
45
        $this->addSql('CREATE INDEX storage_type_idx ON storage (type)');
46
    }
47
48
    public function down(Schema $schema)
49
    {
50
        // create temp table from origin structure
51
        $this->addSql('CREATE TABLE "_new" (
52
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
53
            name VARCHAR(128) NOT NULL,
54
            description TEXT NOT NULL,
55
            type VARCHAR(16) NOT NULL,
56
            path TEXT DEFAULT NULL,
57
            modified DATE DEFAULT NULL
58
        )');
59
60
        $this->addSql('
61
            INSERT INTO
62
                "_new"
63
            SELECT
64
                id,
65
                name,
66
                CASE WHEN description IS NOT NULL
67
                THEN description
68
                ELSE ""
69
                END,
70
                type,
71
                path,
72
                modified
73
            FROM
74
                "storage"
75
        ');
76
        // rename new to origin and drop origin
77
        $this->addSql('ALTER TABLE storage RENAME TO _origin');
78
        $this->addSql('ALTER TABLE _new RENAME TO storage');
79
        $this->addSql('DROP TABLE _origin');
80
81
        $this->addSql('CREATE INDEX storage_type_idx ON storage (type)');
82
    }
83
}
84