]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20180405182455.php
Merge pull request #4152 from ldidry/add-env-var-dev.sh
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20180405182455.php
CommitLineData
7975395d
SV
1<?php
2
3namespace Application\Migrations;
4
7975395d 5use Doctrine\DBAL\Schema\Schema;
877787e5 6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
7975395d
SV
7
8/**
9 * Add archived_at column and set its value to updated_at for is_archived entries.
10 */
877787e5 11class Version20180405182455 extends WallabagMigration
7975395d 12{
7975395d
SV
13 public function up(Schema $schema)
14 {
15 $entryTable = $schema->getTable($this->getTable('entry'));
16
17 $this->skipIf($entryTable->hasColumn('archived_at'), 'It seems that you already played this migration.');
18
19 $entryTable->addColumn('archived_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('archived_at'), 'Unable to add archived_at colum');
28
29 $this->connection->executeQuery(
30 'UPDATE ' . $this->getTable('entry') . ' SET archived_at = updated_at WHERE is_archived = :is_archived',
31 [
32 'is_archived' => true,
33 ]
34 );
35 }
36
7975395d
SV
37 public function down(Schema $schema)
38 {
39 $entryTable = $schema->getTable($this->getTable('entry'));
40
41 $this->skipIf(!$entryTable->hasColumn('archived_at'), 'It seems that you already played this migration.');
42
43 $entryTable->dropColumn('archived_at');
44 }
7975395d 45}