diff options
Diffstat (limited to 'app/DoctrineMigrations/Version20170511211659.php')
-rw-r--r-- | app/DoctrineMigrations/Version20170511211659.php | 100 |
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..d19b5ac5 --- /dev/null +++ b/app/DoctrineMigrations/Version20170511211659.php | |||
@@ -0,0 +1,100 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Application\Migrations; | ||
4 | |||
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; | ||
10 | |||
11 | /** | ||
12 | * Increase the length of the "quote" column of "annotation" table | ||
13 | */ | ||
14 | class 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 | ||
38 | CREATE TEMPORARY TABLE __temp__wallabag_annotation AS | ||
39 | SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges | ||
40 | FROM ${tableName} | ||
41 | EOD | ||
42 | ); | ||
43 | $this->addSql('DROP TABLE ' . $tableName); | ||
44 | $this->addSql(<<<EOD | ||
45 | CREATE 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 | ); | ||
58 | CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id); | ||
59 | CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id); | ||
60 | EOD | ||
61 | ); | ||
62 | |||
63 | $this->addSql(<<<EOD | ||
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; | ||
67 | EOD | ||
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 NOT NULL '); | ||
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) NOT NULL '); | ||
97 | break; | ||
98 | } | ||
99 | } | ||
100 | } | ||