]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/DoctrineMigrations/Version20171008195606.php
Fixed migrations with dash into db name
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20171008195606.php
1 <?php
2
3 namespace Application\Migrations;
4
5 use Doctrine\DBAL\Schema\Schema;
6 use Wallabag\CoreBundle\Doctrine\WallabagMigration;
7
8 /**
9 * Changed reading_time field to prevent null value.
10 */
11 class Version20171008195606 extends WallabagMigration
12 {
13 /**
14 * @param Schema $schema
15 */
16 public function up(Schema $schema)
17 {
18 $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
19
20 switch ($this->connection->getDatabasePlatform()->getName()) {
21 case 'mysql':
22 $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;');
23 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE reading_time reading_time INT(11) NOT NULL;');
24 break;
25 case 'postgresql':
26 $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;');
27 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER COLUMN reading_time SET NOT NULL;');
28 break;
29 }
30 }
31
32 /**
33 * @param Schema $schema
34 */
35 public function down(Schema $schema)
36 {
37 $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
38
39 switch ($this->connection->getDatabasePlatform()->getName()) {
40 case 'mysql':
41 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE reading_time reading_time INT(11);');
42 break;
43 case 'postgresql':
44 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER COLUMN reading_time DROP NOT NULL;');
45 break;
46 }
47 }
48 }