]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20170511211659.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20170511211659.php
CommitLineData
2c3e148b 1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Migrations\SkipMigrationException;
7use Doctrine\DBAL\Schema\Schema;
8use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9use Symfony\Component\DependencyInjection\ContainerInterface;
10
11/**
f808b016 12 * Increase the length of the "quote" column of "annotation" table.
2c3e148b 13 */
14class Version20170511211659 extends AbstractMigration implements ContainerAwareInterface
15{
16 /**
17 * @var ContainerInterface
18 */
19 private $container;
20
21 public function setContainer(ContainerInterface $container = null)
22 {
23 $this->container = $container;
24 }
25
2c3e148b 26 public function up(Schema $schema)
27 {
28 $tableName = $this->getTable('annotation');
29
30 switch ($this->connection->getDatabasePlatform()->getName()) {
31 case 'sqlite':
32 $this->addSql(<<<EOD
33CREATE TEMPORARY TABLE __temp__wallabag_annotation AS
34 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
35 FROM ${tableName}
36EOD
37 );
38 $this->addSql('DROP TABLE ' . $tableName);
39 $this->addSql(<<<EOD
40CREATE TABLE ${tableName}
41(
42 id INTEGER PRIMARY KEY NOT NULL,
43 user_id INTEGER DEFAULT NULL,
44 entry_id INTEGER DEFAULT NULL,
45 text CLOB NOT NULL,
46 created_at DATETIME NOT NULL,
47 updated_at DATETIME NOT NULL,
48 quote CLOB NOT NULL,
49 ranges CLOB 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
52);
53CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id);
54CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id);
55EOD
56 );
57
58 $this->addSql(<<<EOD
59INSERT INTO ${tableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges)
60SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
61FROM __temp__wallabag_annotation;
62EOD
63 );
64 $this->addSql('DROP TABLE __temp__wallabag_annotation');
65 break;
2c3e148b 66 case 'mysql':
f808b016 67 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote TEXT NOT NULL');
2c3e148b 68 break;
2c3e148b 69 case 'postgresql':
f808b016 70 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE TEXT');
2c3e148b 71 break;
72 }
73 }
74
75 public function down(Schema $schema)
76 {
77 $tableName = $this->getTable('annotation');
78
79 switch ($this->connection->getDatabasePlatform()->getName()) {
80 case 'sqlite':
81 throw new SkipMigrationException('Too complex ...');
82 break;
2c3e148b 83 case 'mysql':
f808b016 84 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote VARCHAR(255) NOT NULL');
2c3e148b 85 break;
2c3e148b 86 case 'postgresql':
f808b016 87 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE VARCHAR(255)');
2c3e148b 88 break;
89 }
90 }
f808b016
JB
91
92 private function getTable($tableName)
93 {
94 return $this->container->getParameter('database_table_prefix') . $tableName;
95 }
2c3e148b 96}