]>
Commit | Line | Data |
---|---|---|
07326af5 NL |
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 | private function getTable($tableName) | |
32 | { | |
33 | return $this->container->getParameter('database_table_prefix').$tableName; | |
34 | } | |
35 | ||
36 | /** | |
37 | * @param Schema $schema | |
38 | */ | |
39 | public function up(Schema $schema) | |
40 | { | |
41 | $userTable = $schema->getTable($this->getTable('user')); | |
42 | ||
43 | foreach ($this->fields as $field => $type) { | |
44 | $this->skipIf(!$userTable->hasColumn($field), 'It seems that you already played this migration.'); | |
45 | $userTable->dropColumn($field); | |
46 | } | |
47 | } | |
48 | ||
49 | /** | |
50 | * @param Schema $schema | |
51 | */ | |
52 | public function down(Schema $schema) | |
53 | { | |
54 | $userTable = $schema->getTable($this->getTable('user')); | |
55 | ||
56 | foreach ($this->fields as $field => $type) { | |
57 | $this->skipIf($userTable->hasColumn($field), 'It seems that you already played this migration.'); | |
4acbeb93 | 58 | $userTable->addColumn($field, $type, ['notnull' => false]); |
07326af5 NL |
59 | } |
60 | } | |
61 | } |