]>
Commit | Line | Data |
---|---|---|
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 | public function up(Schema $schema) | |
14 | { | |
15 | $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); | |
16 | ||
17 | switch ($this->connection->getDatabasePlatform()->getName()) { | |
18 | case 'mysql': | |
19 | $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;'); | |
20 | $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE reading_time reading_time INT(11) NOT NULL;'); | |
21 | break; | |
22 | case 'postgresql': | |
23 | $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;'); | |
24 | $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' ALTER COLUMN reading_time SET NOT NULL;'); | |
25 | break; | |
26 | } | |
27 | } | |
28 | ||
29 | public function down(Schema $schema) | |
30 | { | |
31 | $this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); | |
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 | } | |
42 | } |