]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20170511211659.php
Jump to 2.3.6-dev and update release process
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20170511211659.php
CommitLineData
2c3e148b 1<?php
2
3namespace Application\Migrations;
4
2c3e148b 5use Doctrine\DBAL\Migrations\SkipMigrationException;
6use Doctrine\DBAL\Schema\Schema;
bfe7a692 7use Wallabag\CoreBundle\Doctrine\WallabagMigration;
2c3e148b 8
9/**
f808b016 10 * Increase the length of the "quote" column of "annotation" table.
2c3e148b 11 */
bfe7a692 12class Version20170511211659 extends WallabagMigration
2c3e148b 13{
2c3e148b 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
bfe7a692
JB
21CREATE TEMPORARY TABLE __temp__wallabag_annotation AS
22 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
2c3e148b 23 FROM ${tableName}
24EOD
25 );
26 $this->addSql('DROP TABLE ' . $tableName);
27 $this->addSql(<<<EOD
28CREATE 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);
41CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id);
42CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id);
43EOD
44 );
45
46 $this->addSql(<<<EOD
bfe7a692
JB
47INSERT INTO ${tableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges)
48SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
2c3e148b 49FROM __temp__wallabag_annotation;
50EOD
51 );
52 $this->addSql('DROP TABLE __temp__wallabag_annotation');
53 break;
2c3e148b 54 case 'mysql':
f808b016 55 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote TEXT NOT NULL');
2c3e148b 56 break;
2c3e148b 57 case 'postgresql':
f808b016 58 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE TEXT');
2c3e148b 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;
2c3e148b 71 case 'mysql':
f808b016 72 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote VARCHAR(255) NOT NULL');
2c3e148b 73 break;
2c3e148b 74 case 'postgresql':
f808b016 75 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE VARCHAR(255)');
2c3e148b 76 break;
77 }
78 }
79}