]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20160906180558.php
Used createTable
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20160906180558.php
CommitLineData
f1900b68
NL
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
be7a3fd2
NL
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
f1900b68
NL
9
10/**
b115623e 11 * Added group table.
f1900b68 12 */
b115623e 13class Version20160906180558 extends AbstractMigration implements ContainerAwareInterface
f1900b68 14{
be7a3fd2
NL
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 public function setContainer(ContainerInterface $container = null)
21 {
22 $this->container = $container;
23 }
24
25 private function getTable($tableName)
26 {
b115623e 27 return $this->container->getParameter('database_table_prefix').$tableName;
be7a3fd2
NL
28 }
29
f1900b68
NL
30 /**
31 * @param Schema $schema
32 */
33 public function up(Schema $schema)
34 {
b115623e
NL
35 $groupTable = $schema->createTable($this->getTable('group'));
36 $groupTable->addColumn('id', 'integer');
37 $groupTable->addColumn('name', 'string');
38 $groupTable->addColumn('roles', 'blob');
39 $groupTable->setPrimaryKey(['id']);
be7a3fd2 40
b115623e
NL
41 $userGroupTable = $schema->createTable($this->getTable('user_group'));
42 $userGroupTable->addColumn('user_id', 'integer');
43 $userGroupTable->addColumn('group_id', 'integer');
44 $userGroupTable->setPrimaryKey(['user_id', 'group_id']);
be7a3fd2 45
b115623e
NL
46 $userGroupTable->addForeignKeyConstraint(
47 $groupTable,
48 array('group_id'),
49 array('id'),
50 array('onDelete' => 'CASCADE')
51 );
52
53 $userGroupTable->addForeignKeyConstraint(
54 $this->getTable('user'),
55 array('user_id'),
56 array('id'),
57 array('onDelete' => 'CASCADE')
58 );
f1900b68
NL
59 }
60
61 /**
62 * @param Schema $schema
63 */
64 public function down(Schema $schema)
65 {
66 $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\'.');
67
b115623e
NL
68 $schema->dropTable($this->getTable('group'));
69 $schema->dropTable($this->getTable('user_group'));
f1900b68
NL
70 }
71}