From 18fb777b89c6cca529979ab1202eb1af5458bd5d Mon Sep 17 00:00:00 2001 From: adev Date: Fri, 3 Nov 2017 00:41:47 +0100 Subject: Add an initial migration --- app/DoctrineMigrations/Version20160401000000.php | 181 +++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 app/DoctrineMigrations/Version20160401000000.php (limited to 'app/DoctrineMigrations') diff --git a/app/DoctrineMigrations/Version20160401000000.php b/app/DoctrineMigrations/Version20160401000000.php new file mode 100644 index 00000000..34d97d16 --- /dev/null +++ b/app/DoctrineMigrations/Version20160401000000.php @@ -0,0 +1,181 @@ +version->getConfiguration()->getNumberOfExecutedMigrations() > 0) { + $this->version->markMigrated(); + $this->skipIf(true, 'Database already initialized'); + } + + switch ($this->connection->getDatabasePlatform()->getName()) { + case 'sqlite': + $sql = <<addSql($query); + } + + break; + case 'mysql': + $sql = <<addSql($query); + } + break; + + case 'postgresql': + $sql = <<addSql($query); + } + break; + } + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + //TODO: drop tables + } +} -- cgit v1.2.3 From 2680b0bc8c9044b19b80a596f0005a1051b4ee54 Mon Sep 17 00:00:00 2001 From: adev Date: Sat, 4 Nov 2017 21:23:18 +0100 Subject: Fix installation command --- app/DoctrineMigrations/Version20160812120952.php | 28 ++++++++++++++++++++++-- app/DoctrineMigrations/Version20170824113337.php | 7 +++++- 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'app/DoctrineMigrations') diff --git a/app/DoctrineMigrations/Version20160812120952.php b/app/DoctrineMigrations/Version20160812120952.php index 677f30c3..d28f3a71 100644 --- a/app/DoctrineMigrations/Version20160812120952.php +++ b/app/DoctrineMigrations/Version20160812120952.php @@ -30,7 +30,20 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); $this->skipIf($clientsTable->hasColumn('name'), 'It seems that you already played this migration.'); - $clientsTable->addColumn('name', 'blob'); + if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) { + // Can't use $clientsTable->addColumn('name', 'blob'); + // because of the error: + // SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL + $databaseTablePrefix = $this->container->getParameter('database_table_prefix'); + $this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients'); + $this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients'); + $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)'); + $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'); + $this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients'); + $this->addSql('CREATE INDEX IDX_635D765EA76ED395 ON ' . $databaseTablePrefix . 'oauth2_clients (user_id)'); + } else { + $clientsTable->addColumn('name', 'blob'); + } } /** @@ -39,7 +52,18 @@ class Version20160812120952 extends AbstractMigration implements ContainerAwareI public function down(Schema $schema) { $clientsTable = $schema->getTable($this->getTable('oauth2_clients')); - $clientsTable->dropColumn('name'); + + if ('sqlite' === $this->connection->getDatabasePlatform()->getName()) { + $databaseTablePrefix = $this->container->getParameter('database_table_prefix'); + $this->addSql('DROP INDEX IDX_635D765EA76ED395'); + $this->addSql('CREATE TEMPORARY TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients AS SELECT id, random_id, redirect_uris, secret, allowed_grant_types FROM ' . $databaseTablePrefix . 'oauth2_clients'); + $this->addSql('DROP TABLE ' . $databaseTablePrefix . 'oauth2_clients'); + $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))'); + $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'); + $this->addSql('DROP TABLE __temp__' . $databaseTablePrefix . 'oauth2_clients'); + } else { + $clientsTable->dropColumn('name'); + } } private function getTable($tableName) diff --git a/app/DoctrineMigrations/Version20170824113337.php b/app/DoctrineMigrations/Version20170824113337.php index 7393d683..e54a9bcf 100644 --- a/app/DoctrineMigrations/Version20170824113337.php +++ b/app/DoctrineMigrations/Version20170824113337.php @@ -41,7 +41,12 @@ class Version20170824113337 extends AbstractMigration implements ContainerAwareI $entryTable = $schema->getTable($this->getTable('entry')); $this->skipIf(!$entryTable->hasColumn('starred_at'), 'Unable to add starred_at colum'); - $this->connection->executeQuery('UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = true'); + $this->connection->executeQuery( + 'UPDATE ' . $this->getTable('entry') . ' SET starred_at = updated_at WHERE is_starred = :is_starred', + [ + 'is_starred' => true, + ] + ); } /** -- cgit v1.2.3 From 18865cec8621d697e9b174ab4b9203517be5dfcc Mon Sep 17 00:00:00 2001 From: adev Date: Sun, 5 Nov 2017 13:32:22 +0100 Subject: Implements down migration --- app/DoctrineMigrations/Version20160401000000.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'app/DoctrineMigrations') diff --git a/app/DoctrineMigrations/Version20160401000000.php b/app/DoctrineMigrations/Version20160401000000.php index 34d97d16..af135006 100644 --- a/app/DoctrineMigrations/Version20160401000000.php +++ b/app/DoctrineMigrations/Version20160401000000.php @@ -176,6 +176,17 @@ SQL */ public function down(Schema $schema) { - //TODO: drop tables + $this->addSql('DROP TABLE wallabag_craue_config_setting'); + $this->addSql('DROP TABLE "wallabag_tagging_rule"'); + $this->addSql('DROP TABLE "wallabag_config"'); + $this->addSql('DROP TABLE "wallabag_entry"'); + $this->addSql('DROP TABLE wallabag_entry_tag'); + $this->addSql('DROP TABLE "wallabag_tag"'); + $this->addSql('DROP TABLE wallabag_oauth2_refresh_tokens'); + $this->addSql('DROP TABLE wallabag_oauth2_access_tokens'); + $this->addSql('DROP TABLE wallabag_oauth2_clients'); + $this->addSql('DROP TABLE wallabag_oauth2_auth_codes'); + $this->addSql('DROP TABLE "wallabag_user"'); + $this->addSql('DROP TABLE wallabag_annotation'); } } -- cgit v1.2.3 From f4e7a0df0e5917c51889f95e049eda2f81a8416e Mon Sep 17 00:00:00 2001 From: adev Date: Tue, 21 Nov 2017 22:07:37 +0100 Subject: Fix phpcs --- app/DoctrineMigrations/Version20160401000000.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'app/DoctrineMigrations') diff --git a/app/DoctrineMigrations/Version20160401000000.php b/app/DoctrineMigrations/Version20160401000000.php index af135006..a8603abf 100644 --- a/app/DoctrineMigrations/Version20160401000000.php +++ b/app/DoctrineMigrations/Version20160401000000.php @@ -6,7 +6,7 @@ use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; /** - * Initial database structure + * Initial database structure. */ class Version20160401000000 extends AbstractMigration { @@ -22,7 +22,7 @@ class Version20160401000000 extends AbstractMigration switch ($this->connection->getDatabasePlatform()->getName()) { case 'sqlite': - $sql = <<addSql($query); } break; - case 'postgresql': - $sql = <<