]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20171008195606.php
Jump to 2.3.6-dev and update release process
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20171008195606.php
CommitLineData
88bac4a3
NL
1<?php
2
3namespace Application\Migrations;
4
88bac4a3 5use Doctrine\DBAL\Schema\Schema;
bfe7a692 6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
88bac4a3
NL
7
8/**
705d3c38 9 * Changed reading_time field to prevent null value.
88bac4a3 10 */
bfe7a692 11class Version20171008195606 extends WallabagMigration
88bac4a3 12{
88bac4a3
NL
13 /**
14 * @param Schema $schema
15 */
16 public function up(Schema $schema)
17 {
705d3c38 18 $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
88bac4a3
NL
19
20 switch ($this->connection->getDatabasePlatform()->getName()) {
21 case 'mysql':
b3d85e69 22 $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;');
88bac4a3
NL
23 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE reading_time reading_time INT(11) NOT NULL;');
24 break;
25 case 'postgresql':
abce2f05 26 $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;');
88bac4a3
NL
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 {
705d3c38 37 $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
88bac4a3
NL
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 }
88bac4a3 48}