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 public function up(Schema
$schema)
28 $tableName = $this->getTable('annotation');
30 switch ($this->connection
->getDatabasePlatform()->getName()) {
33 CREATE TEMPORARY TABLE __temp__wallabag_annotation AS
34 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
38 $this->addSql('DROP TABLE ' . $tableName);
40 CREATE TABLE ${tableName}
42 id INTEGER PRIMARY KEY NOT NULL,
43 user_id INTEGER DEFAULT NULL,
44 entry_id INTEGER DEFAULT NULL,
46 created_at DATETIME NOT NULL,
47 updated_at DATETIME NOT NULL,
50 CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES wallabag_user (id),
51 CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES wallabag_entry (id) ON DELETE CASCADE
53 CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id);
54 CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id);
59 INSERT INTO ${tableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges)
60 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
61 FROM __temp__wallabag_annotation;
64 $this->addSql('DROP TABLE __temp__wallabag_annotation');
67 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote TEXT NOT NULL');
70 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE TEXT');
75 public function down(Schema
$schema)
77 $tableName = $this->getTable('annotation');
79 switch ($this->connection
->getDatabasePlatform()->getName()) {
81 throw new SkipMigrationException('Too complex ...');
84 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote VARCHAR(255) NOT NULL');
87 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE VARCHAR(255)');
92 private function getTable($tableName)
94 return $this->container
->getParameter('database_table_prefix') . $tableName;