@@ 14-73 (lines=60) @@ | ||
11 | use Doctrine\DBAL\Migrations\AbstractMigration; |
|
12 | use Doctrine\DBAL\Schema\Schema; |
|
13 | ||
14 | 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 |
@@ 14-75 (lines=62) @@ | ||
11 | use Doctrine\DBAL\Migrations\AbstractMigration; |
|
12 | use Doctrine\DBAL\Schema\Schema; |
|
13 | ||
14 | class Version20140609125319_AddTypeForNotices 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 | type VARCHAR(64) NOT NULL DEFAULT "no_type", |
|
23 | date_closed DATETIME DEFAULT NULL, |
|
24 | date_created DATETIME NOT NULL, |
|
25 | date_start DATETIME NOT NULL, |
|
26 | lifetime INTEGER NOT NULL, |
|
27 | status INTEGER NOT NULL, |
|
28 | PRIMARY KEY(id) |
|
29 | )'); |
|
30 | ||
31 | $this->addSql(' |
|
32 | INSERT INTO |
|
33 | "_new" |
|
34 | SELECT |
|
35 | id, message, "no_type", date_closed, date_created, date_start, lifetime, status |
|
36 | FROM |
|
37 | "notice" |
|
38 | '); |
|
39 | // rename new to origin and drop origin |
|
40 | $this->addSql('ALTER TABLE notice RENAME TO _origin'); |
|
41 | $this->addSql('ALTER TABLE _new RENAME TO notice'); |
|
42 | $this->addSql('DROP TABLE _origin'); |
|
43 | ||
44 | $this->addSql('CREATE INDEX notice_show_idx ON notice (date_closed, date_start)'); |
|
45 | } |
|
46 | ||
47 | public function down(Schema $schema) |
|
48 | { |
|
49 | // create temp table from origin structure |
|
50 | $this->addSql('CREATE TABLE "_new" ( |
|
51 | id INTEGER NOT NULL, |
|
52 | message TEXT NOT NULL, |
|
53 | date_closed DATETIME DEFAULT NULL, |
|
54 | date_created DATETIME NOT NULL, |
|
55 | date_start DATETIME NOT NULL, |
|
56 | lifetime INTEGER NOT NULL, |
|
57 | status INTEGER NOT NULL, |
|
58 | PRIMARY KEY(id) |
|
59 | )'); |
|
60 | $this->addSql(' |
|
61 | INSERT INTO |
|
62 | "_new" |
|
63 | SELECT |
|
64 | id, message, date_closed, date_created, date_start, lifetime, status |
|
65 | FROM |
|
66 | "notice" |
|
67 | '); |
|
68 | // rename new to origin and drop origin |
|
69 | $this->addSql('ALTER TABLE notice RENAME TO _origin'); |
|
70 | $this->addSql('ALTER TABLE _new RENAME TO notice'); |
|
71 | $this->addSql('DROP TABLE _origin'); |
|
72 | ||
73 | $this->addSql('CREATE INDEX notice_show_idx ON notice (date_closed, date_created)'); |
|
74 | } |
|
75 | } |
|
76 |