3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\SkipMigrationException
;
6 use Doctrine\DBAL\Schema\Schema
;
7 use Wallabag\CoreBundle\Doctrine\WallabagMigration
;
10 * Increase the length of the "quote" column of "annotation" table.
12 class Version20170511211659
extends WallabagMigration
14 public function up(Schema
$schema)
16 switch ($this->connection
->getDatabasePlatform()->getName()) {
18 $annotationTableName = $this->getTable('annotation', true);
19 $userTableName = $this->getTable('user', true);
20 $entryTableName = $this->getTable('entry', true);
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}
28 $this->addSql('DROP TABLE ' . $annotationTableName);
30 CREATE TABLE ${annotationTableName}
32 id INTEGER PRIMARY KEY NOT NULL,
33 user_id INTEGER DEFAULT NULL,
34 entry_id INTEGER DEFAULT NULL,
36 created_at DATETIME NOT NULL,
37 updated_at DATETIME 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
43 CREATE INDEX IDX_A7AED006A76ED395 ON ${annotationTableName} (user_id);
44 CREATE INDEX IDX_A7AED006BA364942 ON ${annotationTableName} (entry_id);
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;
54 $this->addSql('DROP TABLE __temp__wallabag_annotation');
57 $this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' MODIFY quote TEXT NOT NULL');
60 $this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' ALTER COLUMN quote TYPE TEXT');
65 public function down(Schema
$schema)
67 $tableName = $this->getTable('annotation');
69 switch ($this->connection
->getDatabasePlatform()->getName()) {
71 throw new SkipMigrationException('Too complex ...');
74 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote VARCHAR(255) NOT NULL');
77 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE VARCHAR(255)');