]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/DoctrineMigrations/Version20161128131503.php
9d92983a9ecfa4af44cf774288b5576724251075
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20161128131503.php
1 <?php
2
3 namespace Application\Migrations;
4
5 use Doctrine\DBAL\Migrations\AbstractMigration;
6 use Doctrine\DBAL\Schema\Schema;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11 * Removed locked, credentials_expire_at and expires_at.
12 */
13 class Version20161128131503 extends AbstractMigration implements ContainerAwareInterface
14 {
15 private $fields = [
16 'locked' => 'smallint',
17 'credentials_expire_at' => 'datetime',
18 'expires_at' => 'datetime',
19 ];
20
21 /**
22 * @var ContainerInterface
23 */
24 private $container;
25
26 public function setContainer(ContainerInterface $container = null)
27 {
28 $this->container = $container;
29 }
30
31 /**
32 * @param Schema $schema
33 */
34 public function up(Schema $schema)
35 {
36 $userTable = $schema->getTable($this->getTable('user'));
37
38 foreach ($this->fields as $field => $type) {
39 $this->skipIf(!$userTable->hasColumn($field), 'It seems that you already played this migration.');
40 $userTable->dropColumn($field);
41 }
42 }
43
44 /**
45 * @param Schema $schema
46 */
47 public function down(Schema $schema)
48 {
49 $userTable = $schema->getTable($this->getTable('user'));
50
51 foreach ($this->fields as $field => $type) {
52 $this->skipIf($userTable->hasColumn($field), 'It seems that you already played this migration.');
53 $userTable->addColumn($field, $type, ['notnull' => false]);
54 }
55 }
56
57 private function getTable($tableName)
58 {
59 return $this->container->getParameter('database_table_prefix') . $tableName;
60 }
61 }