aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20170511211659.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/DoctrineMigrations/Version20170511211659.php')
-rw-r--r--app/DoctrineMigrations/Version20170511211659.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20170511211659.php b/app/DoctrineMigrations/Version20170511211659.php
new file mode 100644
index 00000000..f004d1b3
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170511211659.php
@@ -0,0 +1,96 @@
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/**
12 * Increase the length of the "quote" column of "annotation" table.
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
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;
66 case 'mysql':
67 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote TEXT NOT NULL');
68 break;
69 case 'postgresql':
70 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE TEXT');
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;
83 case 'mysql':
84 $this->addSql('ALTER TABLE ' . $tableName . ' MODIFY quote VARCHAR(255) NOT NULL');
85 break;
86 case 'postgresql':
87 $this->addSql('ALTER TABLE ' . $tableName . ' ALTER COLUMN quote TYPE VARCHAR(255)');
88 break;
89 }
90 }
91
92 private function getTable($tableName)
93 {
94 return $this->container->getParameter('database_table_prefix') . $tableName;
95 }
96}