diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-11-28 13:25:18 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-11-28 13:25:18 +0100 |
commit | 07326af5e25f52f54f725898d9fb2f82af60e224 (patch) | |
tree | 708dd8568717409a79f1787197289fae366bc17b /app/DoctrineMigrations/Version20161128131503.php | |
parent | cda0662311c6ae95682d102d4c528edfc71f7c99 (diff) | |
download | wallabag-07326af5e25f52f54f725898d9fb2f82af60e224.tar.gz wallabag-07326af5e25f52f54f725898d9fb2f82af60e224.tar.zst wallabag-07326af5e25f52f54f725898d9fb2f82af60e224.zip |
Added migration to remove useless fields
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..f0e016c8 --- /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); | ||
59 | } | ||
60 | } | ||
61 | } | ||