Version20131223134044_AddNoticeDateStart::up()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 7

Duplication

Lines 29
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 29
loc 29
c 0
b 0
f 0
ccs 0
cts 25
cp 0
rs 8.8571
cc 1
eloc 7
nc 1
nop 1
crap 2
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
namespace AnimeDb\Bundle\AppBundle\DoctrineMigrations;
10
11
use Doctrine\DBAL\Migrations\AbstractMigration;
12
use Doctrine\DBAL\Schema\Schema;
13
14 View Code Duplication
class Version20131223134044_AddNoticeDateStart extends AbstractMigration
15
{
16
    public function up(Schema $schema)
17
    {
18
        // create temp table from new structure
19
        $this->addSql('CREATE TABLE "_new" (
20
            id INTEGER NOT NULL,
21
            message TEXT NOT NULL,
22
            date_closed DATETIME DEFAULT NULL,
23
            date_created DATETIME NOT NULL,
24
            date_start DATETIME NOT NULL,
25
            lifetime INTEGER NOT NULL,
26
            status INTEGER NOT NULL,
27
            PRIMARY KEY(id)
28
        )');
29
30
        $this->addSql('
31
            INSERT INTO
32
                "_new"
33
            SELECT
34
                id, message, date_closed, date_created, date_created, lifetime, status
35
            FROM
36
                "notice"
37
        ');
38
        // rename new to origin and drop origin
39
        $this->addSql('ALTER TABLE notice RENAME TO _origin');
40
        $this->addSql('ALTER TABLE _new RENAME TO notice');
41
        $this->addSql('DROP TABLE _origin');
42
43
        $this->addSql('CREATE INDEX notice_show_idx ON notice (date_closed, date_start)');
44
    }
45
46
    public function down(Schema $schema)
47
    {
48
        // create temp table from origin structure
49
        $this->addSql('CREATE TABLE "_new" (
50
            id INTEGER NOT NULL,
51
            message TEXT NOT NULL,
52
            date_closed DATETIME DEFAULT NULL,
53
            date_created DATETIME NOT NULL,
54
            lifetime INTEGER NOT NULL,
55
            status INTEGER NOT NULL,
56
            PRIMARY KEY(id)
57
        )');
58
        $this->addSql('
59
            INSERT INTO
60
                "_new"
61
            SELECT
62
                id, message, date_closed, date_created, lifetime, status
63
            FROM
64
                "notice"
65
        ');
66
        // rename new to origin and drop origin
67
        $this->addSql('ALTER TABLE notice RENAME TO _origin');
68
        $this->addSql('ALTER TABLE _new RENAME TO notice');
69
        $this->addSql('DROP TABLE _origin');
70
71
        $this->addSql('CREATE INDEX notice_show_idx ON notice (date_closed, date_created)');
72
    }
73
}
74