]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Application\Migrations; | |
4 | ||
5 | use Doctrine\DBAL\Migrations\SkipMigrationException; | |
6 | use Doctrine\DBAL\Schema\Schema; | |
7 | use Wallabag\CoreBundle\Doctrine\WallabagMigration; | |
8 | ||
9 | /** | |
10 | * Increase the length of the "quote" column of "annotation" table. | |
11 | */ | |
12 | class Version20170511211659 extends WallabagMigration | |
13 | { | |
14 | public function up(Schema $schema) | |
15 | { | |
16 | $tableName = $this->getTable('annotation'); | |
17 | ||
18 | switch ($this->connection->getDatabasePlatform()->getName()) { | |
19 | case 'sqlite': | |
20 | $this->addSql(<<<EOD | |
21 | CREATE TEMPORARY TABLE __temp__wallabag_annotation AS | |
22 | SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges | |
23 | FROM ${tableName} | |
24 | EOD | |
25 | ); | |
26 | $this->addSql('DROP TABLE ' . $tableName); | |
27 | $this->addSql(<<<EOD | |
28 | CREATE TABLE ${tableName} | |
29 | ( | |
30 | id INTEGER PRIMARY KEY NOT NULL, | |
31 | user_id INTEGER DEFAULT NULL, | |
32 | entry_id INTEGER DEFAULT NULL, | |
33 | text CLOB NOT NULL, | |
34 | created_at DATETIME NOT NULL, | |
35 | updated_at DATETIME NOT NULL, | |
36 | quote CLOB NOT NULL, | |
37 | ranges CLOB NOT NULL, | |
38 | CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES wallabag_user (id), | |
39 | CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES wallabag_entry (id) ON DELETE CASCADE | |
40 | ); | |
41 | CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id); | |
42 | CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id); | |
43 | EOD | |
44 | ); | |
45 | ||
46 | $this->addSql(<<<EOD | |
47 | INSERT INTO ${tableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges) | |
48 | SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges | |
49 | FROM __temp__wallabag_annotation; | |
50 | EOD | |
51 | ); | |
52 | $this->addSql('DROP TABLE __temp__wallabag_annotation'); | |
53 | break; | |
54 | case 'mysql': | |
55 | $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote TEXT NOT NULL'); | |
56 | break; | |
57 | case 'postgresql': | |
58 | $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE TEXT'); | |
59 | break; | |
60 | } | |
61 | } | |
62 | ||
63 | public function down(Schema $schema) | |
64 | { | |
65 | $tableName = $this->getTable('annotation'); | |
66 | ||
67 | switch ($this->connection->getDatabasePlatform()->getName()) { | |
68 | case 'sqlite': | |
69 | throw new SkipMigrationException('Too complex ...'); | |
70 | break; | |
71 | case 'mysql': | |
72 | $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote VARCHAR(255) NOT NULL'); | |
73 | break; | |
74 | case 'postgresql': | |
75 | $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE VARCHAR(255)'); | |
76 | break; | |
77 | } | |
78 | } | |
79 | } |