]>
Commit | Line | Data |
---|---|---|
88bac4a3 NL |
1 | <?php |
2 | ||
3 | namespace Application\Migrations; | |
4 | ||
88bac4a3 | 5 | use Doctrine\DBAL\Schema\Schema; |
bfe7a692 | 6 | use Wallabag\CoreBundle\Doctrine\WallabagMigration; |
88bac4a3 NL |
7 | |
8 | /** | |
705d3c38 | 9 | * Changed reading_time field to prevent null value. |
88bac4a3 | 10 | */ |
bfe7a692 | 11 | class Version20171008195606 extends WallabagMigration |
88bac4a3 | 12 | { |
88bac4a3 NL |
13 | public function up(Schema $schema) |
14 | { | |
705d3c38 | 15 | $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); |
88bac4a3 NL |
16 | |
17 | switch ($this->connection->getDatabasePlatform()->getName()) { | |
18 | case 'mysql': | |
b3d85e69 | 19 | $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;'); |
88bac4a3 NL |
20 | $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE reading_time reading_time INT(11) NOT NULL;'); |
21 | break; | |
22 | case 'postgresql': | |
abce2f05 | 23 | $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;'); |
88bac4a3 NL |
24 | $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER COLUMN reading_time SET NOT NULL;'); |
25 | break; | |
26 | } | |
27 | } | |
28 | ||
88bac4a3 NL |
29 | public function down(Schema $schema) |
30 | { | |
705d3c38 | 31 | $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); |
88bac4a3 NL |
32 | |
33 | switch ($this->connection->getDatabasePlatform()->getName()) { | |
34 | case 'mysql': | |
35 | $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE reading_time reading_time INT(11);'); | |
36 | break; | |
37 | case 'postgresql': | |
38 | $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER COLUMN reading_time DROP NOT NULL;'); | |
39 | break; | |
40 | } | |
41 | } | |
88bac4a3 | 42 | } |