]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20170824113337.php
Merge pull request #4438 from wallabag/dependabot/composer/scheb/two-factor-bundle...
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20170824113337.php
CommitLineData
a991c46e
F
1<?php
2
3namespace Application\Migrations;
4
a991c46e 5use Doctrine\DBAL\Schema\Schema;
bfe7a692 6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
a991c46e
F
7
8/**
9 * Add starred_at column and set its value to updated_at for is_starred entries.
10 */
bfe7a692 11class Version20170824113337 extends WallabagMigration
a991c46e 12{
a991c46e
F
13 public function up(Schema $schema)
14 {
15 $entryTable = $schema->getTable($this->getTable('entry'));
16
17 $this->skipIf($entryTable->hasColumn('starred_at'), 'It seems that you already played this migration.');
18
19 $entryTable->addColumn('starred_at', 'datetime', [
20 'notnull' => false,
21 ]);
22 }
23
24 public function postUp(Schema $schema)
25 {
26 $entryTable = $schema->getTable($this->getTable('entry'));
27 $this->skipIf(!$entryTable->hasColumn('starred_at'), 'Unable to add starred_at colum');
28
2680b0bc 29 $this->connection->executeQuery(
30 'UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = :is_starred',
31 [
32 'is_starred' => true,
33 ]
34 );
a991c46e
F
35 }
36
a991c46e
F
37 public function down(Schema $schema)
38 {
39 $entryTable = $schema->getTable($this->getTable('entry'));
40
41 $this->skipIf(!$entryTable->hasColumn('starred_at'), 'It seems that you already played this migration.');
42
43 $entryTable->dropColumn('starred_at');
44 }
a991c46e 45}