3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\AbstractMigration
;
6 use Doctrine\DBAL\Migrations\SkipMigrationException
;
7 use Doctrine\DBAL\Schema\Schema
;
8 use Symfony\Component\DependencyInjection\ContainerAwareInterface
;
9 use Symfony\Component\DependencyInjection\ContainerInterface
;
12 * Increase the length of the "quote" column of "annotation" table
14 class Version20170511211659
extends AbstractMigration
implements ContainerAwareInterface
17 * @var ContainerInterface
21 public function setContainer(ContainerInterface
$container = null)
23 $this->container
= $container;
26 private function getTable($tableName)
28 return $this->container
->getParameter('database_table_prefix') . $tableName;
31 public function up(Schema
$schema)
33 $tableName = $this->getTable('annotation');
35 switch ($this->connection
->getDatabasePlatform()->getName()) {
38 CREATE TEMPORARY TABLE __temp__wallabag_annotation AS
39 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
43 $this->addSql('DROP TABLE ' . $tableName);
45 CREATE TABLE ${tableName}
47 id INTEGER PRIMARY KEY NOT NULL,
48 user_id INTEGER DEFAULT NULL,
49 entry_id INTEGER DEFAULT NULL,
51 created_at DATETIME NOT NULL,
52 updated_at DATETIME NOT NULL,
55 CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES wallabag_user (id),
56 CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES wallabag_entry (id) ON DELETE CASCADE
58 CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id);
59 CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id);
64 INSERT INTO ${tableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges)
65 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
66 FROM __temp__wallabag_annotation;
69 $this->addSql('DROP TABLE __temp__wallabag_annotation');
73 $this->addSql('ALTER TABLE '.$tableName.' MODIFY quote TEXT NOT NULL');
77 $this->addSql('ALTER TABLE '.$tableName.' ALTER COLUMN quote TYPE TEXT');
82 public function down(Schema
$schema)
84 $tableName = $this->getTable('annotation');
86 switch ($this->connection
->getDatabasePlatform()->getName()) {
88 throw new SkipMigrationException('Too complex ...');
92 $this->addSql('ALTER TABLE '.$tableName.' MODIFY quote VARCHAR(255) NOT NULL');
96 $this->addSql('ALTER TABLE '.$tableName.' ALTER COLUMN quote TYPE VARCHAR(255)');