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