]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20161214094402.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20161214094402.php
CommitLineData
5ed503ab
NL
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/**
01736b5a 11 * Renamed uuid to uid in entry table.
5ed503ab
NL
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
5ed503ab
NL
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':
f808b016
JB
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;');
6dfd1a6c 40 $this->addSql('DROP TABLE __temp__wallabag_entry');
5ed503ab
NL
41 break;
42 case 'mysql':
f808b016 43 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE uuid uid VARCHAR(23)');
5ed503ab
NL
44 break;
45 case 'postgresql':
f808b016 46 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' RENAME uuid TO uid');
5ed503ab
NL
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':
6dfd1a6c 61 throw new SkipMigrationException('Too complex ...');
5ed503ab
NL
62 break;
63 case 'mysql':
f808b016 64 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE uid uuid VARCHAR(23)');
5ed503ab
NL
65 break;
66 case 'postgresql':
f808b016 67 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' RENAME uid TO uuid');
5ed503ab
NL
68 }
69 }
f808b016
JB
70
71 private function getTable($tableName)
72 {
73 return $this->container->getParameter('database_table_prefix') . $tableName;
74 }
5ed503ab 75}