aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-06-07 16:30:27 +0200
committerGitHub <noreply@github.com>2017-06-07 16:30:27 +0200
commit7bb3aa31776ffce2735a3b16f6ad80bb17946d4d (patch)
tree5dd6bae023e67731479a8f799f3e00780ac98c56 /app/DoctrineMigrations
parentc0d756f67d1cc0fc6832d404a09729f9219f0595 (diff)
parentc406cef5b69b0d6c43adef33b5374b209347b637 (diff)
downloadwallabag-7bb3aa31776ffce2735a3b16f6ad80bb17946d4d.tar.gz
wallabag-7bb3aa31776ffce2735a3b16f6ad80bb17946d4d.tar.zst
wallabag-7bb3aa31776ffce2735a3b16f6ad80bb17946d4d.zip
Merge pull request #3093 from aaa2000/annotation-error-on-save
Displays an error with an annotation with a too long quote
Diffstat (limited to 'app/DoctrineMigrations')
-rw-r--r--app/DoctrineMigrations/Version20170511211659.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20170511211659.php b/app/DoctrineMigrations/Version20170511211659.php
new file mode 100644
index 00000000..f2d5cf5e
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170511211659.php
@@ -0,0 +1,100 @@
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 private function getTable($tableName)
27 {
28 return $this->container->getParameter('database_table_prefix') . $tableName;
29 }
30
31 public function up(Schema $schema)
32 {
33 $tableName = $this->getTable('annotation');
34
35 switch ($this->connection->getDatabasePlatform()->getName()) {
36 case 'sqlite':
37 $this->addSql(<<<EOD
38CREATE TEMPORARY TABLE __temp__wallabag_annotation AS
39 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
40 FROM ${tableName}
41EOD
42 );
43 $this->addSql('DROP TABLE ' . $tableName);
44 $this->addSql(<<<EOD
45CREATE TABLE ${tableName}
46(
47 id INTEGER PRIMARY KEY NOT NULL,
48 user_id INTEGER DEFAULT NULL,
49 entry_id INTEGER DEFAULT NULL,
50 text CLOB NOT NULL,
51 created_at DATETIME NOT NULL,
52 updated_at DATETIME NOT NULL,
53 quote CLOB NOT NULL,
54 ranges CLOB 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
57);
58CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id);
59CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id);
60EOD
61 );
62
63 $this->addSql(<<<EOD
64INSERT INTO ${tableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges)
65SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
66FROM __temp__wallabag_annotation;
67EOD
68 );
69 $this->addSql('DROP TABLE __temp__wallabag_annotation');
70 break;
71
72 case 'mysql':
73 $this->addSql('ALTER TABLE '.$tableName.' MODIFY quote TEXT NOT NULL');
74 break;
75
76 case 'postgresql':
77 $this->addSql('ALTER TABLE '.$tableName.' ALTER COLUMN quote TYPE TEXT');
78 break;
79 }
80 }
81
82 public function down(Schema $schema)
83 {
84 $tableName = $this->getTable('annotation');
85
86 switch ($this->connection->getDatabasePlatform()->getName()) {
87 case 'sqlite':
88 throw new SkipMigrationException('Too complex ...');
89 break;
90
91 case 'mysql':
92 $this->addSql('ALTER TABLE '.$tableName.' MODIFY quote VARCHAR(255) NOT NULL');
93 break;
94
95 case 'postgresql':
96 $this->addSql('ALTER TABLE '.$tableName.' ALTER COLUMN quote TYPE VARCHAR(255)');
97 break;
98 }
99 }
100}