]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Application\Migrations; | |
4 | ||
5 | use Doctrine\DBAL\Schema\Schema; | |
6 | use Wallabag\CoreBundle\Doctrine\WallabagMigration; | |
7 | ||
8 | /** | |
9 | * Added user_id column on oauth2_clients to prevent users to delete API clients from other users. | |
10 | */ | |
11 | class Version20161024212538 extends WallabagMigration | |
12 | { | |
13 | private $constraintName = 'IDX_user_oauth_client'; | |
14 | ||
15 | public function up(Schema $schema) | |
16 | { | |
17 | $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); | |
18 | ||
19 | $this->skipIf($clientsTable->hasColumn('user_id'), 'It seems that you already played this migration.'); | |
20 | ||
21 | $clientsTable->addColumn('user_id', 'integer', ['notnull' => false]); | |
22 | ||
23 | $clientsTable->addForeignKeyConstraint( | |
24 | $this->getTable('user'), | |
25 | ['user_id'], | |
26 | ['id'], | |
27 | ['onDelete' => 'CASCADE'], | |
28 | $this->constraintName | |
29 | ); | |
30 | } | |
31 | ||
32 | public function down(Schema $schema) | |
33 | { | |
34 | $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); | |
35 | ||
36 | $this->skipIf(!$clientsTable->hasColumn('user_id'), 'It seems that you already played this migration.'); | |
37 | ||
38 | $clientsTable->dropColumn('user_id', 'integer'); | |
39 | ||
40 | if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) { | |
41 | $clientsTable->removeForeignKey($this->constraintName); | |
42 | } | |
43 | } | |
44 | } |