]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20161024212538.php
Merge pull request #4310 from wallabag/fix/4216
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20161024212538.php
CommitLineData
23406ca3
NL
1<?php
2
3namespace Application\Migrations;
4
23406ca3 5use Doctrine\DBAL\Schema\Schema;
bfe7a692 6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
23406ca3 7
b87f1712 8/**
01736b5a 9 * Added user_id column on oauth2_clients to prevent users to delete API clients from other users.
b87f1712 10 */
bfe7a692 11class Version20161024212538 extends WallabagMigration
23406ca3 12{
4acbeb93
NL
13 private $constraintName = 'IDX_user_oauth_client';
14
23406ca3
NL
15 public function up(Schema $schema)
16 {
84c6a48d 17 $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
23406ca3 18
84c6a48d 19 $this->skipIf($clientsTable->hasColumn('user_id'), 'It seems that you already played this migration.');
18d7bc3a 20
4acbeb93 21 $clientsTable->addColumn('user_id', 'integer', ['notnull' => false]);
84c6a48d
NL
22
23 $clientsTable->addForeignKeyConstraint(
24 $this->getTable('user'),
65a8c6e1
NL
25 ['user_id'],
26 ['id'],
4acbeb93
NL
27 ['onDelete' => 'CASCADE'],
28 $this->constraintName
84c6a48d 29 );
23406ca3
NL
30 }
31
23406ca3
NL
32 public function down(Schema $schema)
33 {
4acbeb93
NL
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
3ef055ce 40 if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) {
4acbeb93
NL
41 $clientsTable->removeForeignKey($this->constraintName);
42 }
23406ca3
NL
43 }
44}