Version20131004103102_AddStorageLastModified::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 Version20131004103102_AddStorageLastModified 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 NOT 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, NULL
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
        )');
58
        $this->addSql('
59
            INSERT INTO
60
                "_new"
61
            SELECT
62
                id, name, description, type, path
63
            FROM
64
                "storage"
65
        ');
66
        // rename new to origin and drop origin
67
        $this->addSql('ALTER TABLE storage RENAME TO _origin');
68
        $this->addSql('ALTER TABLE _new RENAME TO storage');
69
        $this->addSql('DROP TABLE _origin');
70
71
        $this->addSql('CREATE INDEX storage_type_idx ON storage (type)');
72
    }
73
}
74