diff options
Diffstat (limited to 'app/DoctrineMigrations/Version20161128131503.php')
-rw-r--r-- | app/DoctrineMigrations/Version20161128131503.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20161128131503.php b/app/DoctrineMigrations/Version20161128131503.php new file mode 100644 index 00000000..b71aa38b --- /dev/null +++ b/app/DoctrineMigrations/Version20161128131503.php | |||
@@ -0,0 +1,61 @@ | |||
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.'); | ||
58 | $userTable->addColumn($field, $type, ['notnull' => false]); | ||
59 | } | ||
60 | } | ||
61 | } | ||