]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20170824113337.php
Fixed migrations with dash into db name
[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 /**
14 * @param Schema $schema
15 */
16 public function up(Schema $schema)
17 {
18 $entryTable = $schema->getTable($this->getTable('entry'));
19
20 $this->skipIf($entryTable->hasColumn('starred_at'), 'It seems that you already played this migration.');
21
22 $entryTable->addColumn('starred_at', 'datetime', [
23 'notnull' => false,
24 ]);
25 }
26
27 public function postUp(Schema $schema)
28 {
29 $entryTable = $schema->getTable($this->getTable('entry'));
30 $this->skipIf(!$entryTable->hasColumn('starred_at'), 'Unable to add starred_at colum');
31
2680b0bc 32 $this->connection->executeQuery(
33 'UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = :is_starred',
34 [
35 'is_starred' => true,
36 ]
37 );
a991c46e
F
38 }
39
40 /**
41 * @param Schema $schema
42 */
43 public function down(Schema $schema)
44 {
45 $entryTable = $schema->getTable($this->getTable('entry'));
46
47 $this->skipIf(!$entryTable->hasColumn('starred_at'), 'It seems that you already played this migration.');
48
49 $entryTable->dropColumn('starred_at');
50 }
a991c46e 51}