aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20161128131503.php
blob: b71aa38bcbe6fc5cab9edf1ac6b4642138332b1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Removed locked, credentials_expire_at and expires_at.
 */
class Version20161128131503 extends AbstractMigration implements ContainerAwareInterface
{
    private $fields = [
        'locked' => 'smallint',
        'credentials_expire_at' => 'datetime',
        'expires_at' => 'datetime',
    ];

    /**
     * @var ContainerInterface
     */
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    private function getTable($tableName)
    {
        return $this->container->getParameter('database_table_prefix').$tableName;
    }

    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        $userTable = $schema->getTable($this->getTable('user'));

        foreach ($this->fields as $field => $type) {
            $this->skipIf(!$userTable->hasColumn($field), 'It seems that you already played this migration.');
            $userTable->dropColumn($field);
        }
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema)
    {
        $userTable = $schema->getTable($this->getTable('user'));

        foreach ($this->fields as $field => $type) {
            $this->skipIf($userTable->hasColumn($field), 'It seems that you already played this migration.');
            $userTable->addColumn($field, $type, ['notnull' => false]);
        }
    }
}