]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20160812120952.php
Merge pull request #4438 from wallabag/dependabot/composer/scheb/two-factor-bundle...
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20160812120952.php
CommitLineData
9c545fe0
TC
1<?php
2
3namespace Application\Migrations;
4
9c545fe0 5use Doctrine\DBAL\Schema\Schema;
bfe7a692 6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
9c545fe0 7
b87f1712 8/**
01736b5a 9 * Added name field on wallabag_oauth2_clients.
b87f1712 10 */
bfe7a692 11class Version20160812120952 extends WallabagMigration
9c545fe0 12{
9c545fe0
TC
13 public function up(Schema $schema)
14 {
597755b8
NL
15 $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
16 $this->skipIf($clientsTable->hasColumn('name'), 'It seems that you already played this migration.');
18d7bc3a 17
2680b0bc 18 if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) {
19 // Can't use $clientsTable->addColumn('name', 'blob');
20 // because of the error:
21 // SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL
22 $databaseTablePrefix = $this->container->getParameter('database_table_prefix');
23 $this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients');
24 $this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients');
25 $this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, user_id INTEGER DEFAULT NULL, random_id VARCHAR(255) NOT NULL COLLATE BINARY, secret VARCHAR(255) NOT NULL COLLATE BINARY, redirect_uris CLOB NOT NULL, allowed_grant_types CLOB NOT NULL, name CLOB NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_635D765EA76ED395 FOREIGN KEY (user_id) REFERENCES "' . $databaseTablePrefix . 'user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
26 $this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients');
27 $this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients');
28 $this->addSql('CREATE INDEX IDX_635D765EA76ED395 ON ' . $databaseTablePrefix . 'oauth2_clients (user_id)');
29 } else {
30 $clientsTable->addColumn('name', 'blob');
31 }
9c545fe0
TC
32 }
33
9c545fe0
TC
34 public function down(Schema $schema)
35 {
597755b8 36 $clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
2680b0bc 37
38 if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) {
39 $databaseTablePrefix = $this->container->getParameter('database_table_prefix');
40 $this->addSql('DROP INDEX IDX_635D765EA76ED395');
41 $this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients');
42 $this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients');
43 $this->addSql('CREATE TABLE ' . $databaseTablePrefix . 'oauth2_clients (id INTEGER NOT NULL, random_id VARCHAR(255) NOT NULL, secret VARCHAR(255) NOT NULL, redirect_uris CLOB NOT NULL COLLATE BINARY, allowed_grant_types CLOB NOT NULL COLLATE BINARY, PRIMARY KEY(id))');
44 $this->addSql('INSERT INTO ' . $databaseTablePrefix . 'oauth2_clients (id, random_id, redirect_uris, secret, allowed_grant_types) SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM __temp__' . $databaseTablePrefix . 'oauth2_clients');
45 $this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients');
46 } else {
47 $clientsTable->dropColumn('name');
48 }
9c545fe0
TC
49 }
50}