]> git.immae.eu Git - github/wallabag/wallabag.git/blame_incremental - app/DoctrineMigrations/Version20161214094402.php
Merge pull request #3326 from nclsHart/reload-entry-command
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20161214094402.php
... / ...
CommitLineData
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
10/**
11 * Renamed uuid to uid in entry table.
12 */
13class Version20161214094402 extends AbstractMigration implements ContainerAwareInterface
14{
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 public function setContainer(ContainerInterface $container = null)
21 {
22 $this->container = $container;
23 }
24
25 /**
26 * @param Schema $schema
27 */
28 public function up(Schema $schema)
29 {
30 $entryTable = $schema->getTable($this->getTable('entry'));
31
32 $this->skipIf($entryTable->hasColumn('uid'), 'It seems that you already played this migration.');
33
34 switch ($this->connection->getDatabasePlatform()->getName()) {
35 case 'sqlite':
36 $this->addSql('CREATE TEMPORARY TABLE __temp__wallabag_entry AS SELECT id, user_id, uuid, title, url, is_archived, is_starred, content, created_at, updated_at, mimetype, language, reading_time, domain_name, preview_picture, is_public FROM ' . $this->getTable('entry'));
37 $this->addSql('DROP TABLE ' . $this->getTable('entry'));
38 $this->addSql('CREATE TABLE ' . $this->getTable('entry') . ' (id INTEGER NOT NULL, user_id INTEGER DEFAULT NULL, uid CLOB DEFAULT NULL COLLATE BINARY, title CLOB DEFAULT NULL COLLATE BINARY, url CLOB DEFAULT NULL COLLATE BINARY, is_archived BOOLEAN NOT NULL, is_starred BOOLEAN NOT NULL, content CLOB DEFAULT NULL COLLATE BINARY, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, mimetype CLOB DEFAULT NULL COLLATE BINARY, language CLOB DEFAULT NULL COLLATE BINARY, reading_time INTEGER DEFAULT NULL, domain_name CLOB DEFAULT NULL COLLATE BINARY, preview_picture CLOB DEFAULT NULL COLLATE BINARY, is_public BOOLEAN DEFAULT "0", PRIMARY KEY(id));');
39 $this->addSql('INSERT INTO ' . $this->getTable('entry') . ' (id, user_id, uid, title, url, is_archived, is_starred, content, created_at, updated_at, mimetype, language, reading_time, domain_name, preview_picture, is_public) SELECT id, user_id, uuid, title, url, is_archived, is_starred, content, created_at, updated_at, mimetype, language, reading_time, domain_name, preview_picture, is_public FROM __temp__wallabag_entry;');
40 $this->addSql('DROP TABLE __temp__wallabag_entry');
41 break;
42 case 'mysql':
43 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE uuid uid VARCHAR(23)');
44 break;
45 case 'postgresql':
46 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' RENAME uuid TO uid');
47 }
48 }
49
50 /**
51 * @param Schema $schema
52 */
53 public function down(Schema $schema)
54 {
55 $entryTable = $schema->getTable($this->getTable('entry'));
56
57 $this->skipIf($entryTable->hasColumn('uuid'), 'It seems that you already played this migration.');
58
59 switch ($this->connection->getDatabasePlatform()->getName()) {
60 case 'sqlite':
61 throw new SkipMigrationException('Too complex ...');
62 break;
63 case 'mysql':
64 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE uid uuid VARCHAR(23)');
65 break;
66 case 'postgresql':
67 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' RENAME uid TO uuid');
68 }
69 }
70
71 private function getTable($tableName)
72 {
73 return $this->container->getParameter('database_table_prefix') . $tableName;
74 }
75}