Code Duplication    Length = 62-64 lines in 3 locations

src/DoctrineMigrations/Version20131225130333_AddItemStudio.php 1 location

@@ 88-149 (lines=62) @@
85
        $this->updateItemStudio();
86
    }
87
88
    public function down(Schema $schema)
89
    {
90
        // create temp table from origin structure
91
        $this->addSql('CREATE TABLE "_new" (
92
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
93
            type VARCHAR(16) DEFAULT NULL,
94
            country VARCHAR(2) DEFAULT NULL,
95
            storage INTEGER DEFAULT NULL,
96
            name VARCHAR(256) NOT NULL,
97
            date_start DATE NOT NULL,
98
            date_end DATE DEFAULT NULL,
99
            duration INTEGER DEFAULT NULL,
100
            summary TEXT DEFAULT NULL,
101
            path VARCHAR(256) DEFAULT NULL,
102
            episodes TEXT DEFAULT NULL,
103
            episodes_number VARCHAR(5) DEFAULT NULL,
104
            translate VARCHAR(256) DEFAULT NULL,
105
            file_info TEXT DEFAULT NULL,
106
            cover VARCHAR(256) DEFAULT NULL,
107
            rating INTEGER DEFAULT NULL,
108
            date_add DATETIME NOT NULL,
109
            date_update DATETIME NOT NULL
110
        )');
111
        $this->addSql('
112
            INSERT INTO
113
                "_new"
114
            SELECT
115
                id,
116
                type,
117
                country,
118
                storage,
119
                name,
120
                date_start,
121
                date_end,
122
                duration,
123
                summary,
124
                path,
125
                episodes,
126
                episodes_number,
127
                translate,
128
                file_info,
129
                cover,
130
                rating,
131
                date_add,
132
                date_update
133
            FROM
134
                "item"
135
        ');
136
        // rename new to origin and drop origin
137
        $this->addSql('ALTER TABLE item RENAME TO _origin');
138
        $this->addSql('ALTER TABLE _new RENAME TO item');
139
        $this->addSql('DROP TABLE _origin');
140
141
        // create index
142
        $this->addSql('CREATE INDEX item_country_idx ON item (country);');
143
        $this->addSql('CREATE INDEX item_storage_idx ON item (storage);');
144
        $this->addSql('CREATE INDEX item_type_idx ON item (type)');
145
        $this->addSql('CREATE INDEX item_rating_idx ON item (rating)');
146
147
        // drop table
148
        $schema->dropTable('studio');
149
    }
150
151
    protected function createTableStudio(Schema $schema)
152
    {

src/DoctrineMigrations/Version20140122122107_RenameItemDateStartToDatePremiere.php 2 locations

@@ 20-81 (lines=62) @@
17
 */
18
class Version20140122122107_RenameItemDateStartToDatePremiere extends AbstractMigration
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
            type VARCHAR(16) DEFAULT NULL,
26
            country VARCHAR(2) DEFAULT NULL,
27
            storage INTEGER DEFAULT NULL,
28
            studio INTEGER DEFAULT NULL,
29
            name VARCHAR(256) NOT NULL,
30
            date_premiere DATE DEFAULT NULL,
31
            date_end DATE DEFAULT NULL,
32
            duration INTEGER DEFAULT NULL,
33
            summary TEXT DEFAULT NULL,
34
            path VARCHAR(256) DEFAULT NULL,
35
            episodes TEXT DEFAULT NULL,
36
            episodes_number VARCHAR(5) DEFAULT NULL,
37
            translate VARCHAR(256) DEFAULT NULL,
38
            file_info TEXT DEFAULT NULL,
39
            cover VARCHAR(256) DEFAULT NULL,
40
            rating INTEGER DEFAULT NULL,
41
            date_add DATETIME NOT NULL,
42
            date_update DATETIME NOT NULL
43
        )');
44
        $this->addSql('
45
            INSERT INTO
46
                "_new"
47
            SELECT
48
                id,
49
                type,
50
                country,
51
                storage,
52
                studio,
53
                name,
54
                date_start,
55
                date_end,
56
                duration,
57
                summary,
58
                path,
59
                episodes,
60
                episodes_number,
61
                translate,
62
                file_info,
63
                cover,
64
                rating,
65
                date_add,
66
                date_update
67
            FROM
68
                "item"
69
        ');
70
        // rename new to origin and drop origin
71
        $this->addSql('ALTER TABLE item RENAME TO _origin');
72
        $this->addSql('ALTER TABLE _new RENAME TO item');
73
        $this->addSql('DROP TABLE _origin');
74
75
        // create index
76
        $this->addSql('CREATE INDEX item_country_idx ON item (country);');
77
        $this->addSql('CREATE INDEX item_storage_idx ON item (storage);');
78
        $this->addSql('CREATE INDEX item_type_idx ON item (type)');
79
        $this->addSql('CREATE INDEX item_rating_idx ON item (rating)');
80
        $this->addSql('CREATE INDEX item_studio_idx ON item (studio)');
81
    }
82
83
    public function down(Schema $schema)
84
    {
@@ 83-146 (lines=64) @@
80
        $this->addSql('CREATE INDEX item_studio_idx ON item (studio)');
81
    }
82
83
    public function down(Schema $schema)
84
    {
85
        // create temp table from origin structure
86
        $this->addSql('CREATE TABLE "_new" (
87
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
88
            type VARCHAR(16) DEFAULT NULL,
89
            country VARCHAR(2) DEFAULT NULL,
90
            storage INTEGER DEFAULT NULL,
91
            studio INTEGER DEFAULT NULL,
92
            name VARCHAR(256) NOT NULL,
93
            date_start DATE NOT NULL,
94
            date_end DATE DEFAULT NULL,
95
            duration INTEGER DEFAULT NULL,
96
            summary TEXT DEFAULT NULL,
97
            path VARCHAR(256) DEFAULT NULL,
98
            episodes TEXT DEFAULT NULL,
99
            episodes_number VARCHAR(5) DEFAULT NULL,
100
            translate VARCHAR(256) DEFAULT NULL,
101
            file_info TEXT DEFAULT NULL,
102
            cover VARCHAR(256) DEFAULT NULL,
103
            rating INTEGER DEFAULT NULL,
104
            date_add DATETIME NOT NULL,
105
            date_update DATETIME NOT NULL
106
        )');
107
        $this->addSql('
108
            INSERT INTO
109
                "_new"
110
            SELECT
111
                id,
112
                type,
113
                country,
114
                storage,
115
                studio,
116
                name,
117
                CASE WHEN date_premiere IS NOT NULL
118
                THEN date_premiere
119
                ELSE "'.date('Y-m-d H:i:s').'"
120
                END,
121
                date_end,
122
                duration,
123
                summary,
124
                path,
125
                episodes,
126
                episodes_number,
127
                translate,
128
                file_info,
129
                cover,
130
                rating,
131
                date_add,
132
                date_update
133
            FROM
134
                "item"
135
        ');
136
        // rename new to origin and drop origin
137
        $this->addSql('ALTER TABLE item RENAME TO _origin');
138
        $this->addSql('ALTER TABLE _new RENAME TO item');
139
        $this->addSql('DROP TABLE _origin');
140
141
        // create index
142
        $this->addSql('CREATE INDEX item_country_idx ON item (country);');
143
        $this->addSql('CREATE INDEX item_storage_idx ON item (storage);');
144
        $this->addSql('CREATE INDEX item_type_idx ON item (type)');
145
        $this->addSql('CREATE INDEX item_rating_idx ON item (rating)');
146
    }
147
}
148