]> git.immae.eu Git - github/wallabag/wallabag.git/blob - Version20170511211659.php
d0752bafec74b48d671c1d1bc5a0ed9fe17c112f
[github/wallabag/wallabag.git] / Version20170511211659.php
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 switch ($this->connection->getDatabasePlatform()->getName()) {
17 case 'sqlite':
18 $annotationTableName = $this->getTable('annotation', true);
19 $userTableName = $this->getTable('user', true);
20 $entryTableName = $this->getTable('entry', true);
21
22 $this->addSql(<<<EOD
23 CREATE TEMPORARY TABLE __temp__wallabag_annotation AS
24 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
25 FROM ${annotationTableName}
26 EOD
27 );
28 $this->addSql('DROP TABLE ' . $annotationTableName);
29 $this->addSql(<<<EOD
30 CREATE TABLE ${annotationTableName}
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,
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
42 );
43 CREATE INDEX IDX_A7AED006A76ED395 ON ${annotationTableName} (user_id);
44 CREATE INDEX IDX_A7AED006BA364942 ON ${annotationTableName} (entry_id);
45 EOD
46 );
47
48 $this->addSql(<<<EOD
49 INSERT INTO ${annotationTableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges)
50 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
51 FROM __temp__wallabag_annotation;
52 EOD
53 );
54 $this->addSql('DROP TABLE __temp__wallabag_annotation');
55 break;
56 case 'mysql':
57 $this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' MODIFY quote TEXT NOT NULL');
58 break;
59 case 'postgresql':
60 $this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' ALTER COLUMN quote TYPE TEXT');
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;
73 case 'mysql':
74 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote VARCHAR(255) NOT NULL');
75 break;
76 case 'postgresql':
77 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE VARCHAR(255)');
78 break;
79 }
80 }
81 }