]>
Commit | Line | Data |
---|---|---|
23406ca3 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 | ||
b87f1712 NL |
10 | /** |
11 | * Added user_id column on oauth2_clients to prevent users to delete API clients from other users | |
12 | */ | |
23406ca3 NL |
13 | class Version20161024212538 extends AbstractMigration implements ContainerAwareInterface |
14 | { | |
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 | { | |
18d7bc3a | 27 | return $this->container->getParameter('database_table_prefix').$tableName; |
23406ca3 NL |
28 | } |
29 | ||
30 | /** | |
31 | * @param Schema $schema | |
32 | */ | |
33 | public function up(Schema $schema) | |
34 | { | |
84c6a48d | 35 | $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); |
23406ca3 | 36 | |
84c6a48d | 37 | $this->skipIf($clientsTable->hasColumn('user_id'), 'It seems that you already played this migration.'); |
18d7bc3a | 38 | |
84c6a48d NL |
39 | $clientsTable->addColumn('user_id', 'integer'); |
40 | ||
41 | $clientsTable->addForeignKeyConstraint( | |
42 | $this->getTable('user'), | |
65a8c6e1 NL |
43 | ['user_id'], |
44 | ['id'], | |
45 | ['onDelete' => 'CASCADE'] | |
84c6a48d | 46 | ); |
23406ca3 NL |
47 | } |
48 | ||
49 | /** | |
50 | * @param Schema $schema | |
51 | */ | |
52 | public function down(Schema $schema) | |
53 | { | |
23406ca3 NL |
54 | } |
55 | } |