From ed840f7f2cfde199f539781a95982b0eadc6db80 Mon Sep 17 00:00:00 2001 From: Seth Shaw Date: Tue, 5 Jun 2018 18:32:49 -0700 Subject: [PATCH] add postgresql migration (#47) * add postgresql migration * abort gemini table migration if db is not supported --- .../src/Migrations/Version20180530031926.php | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/Gemini/src/Migrations/Version20180530031926.php b/Gemini/src/Migrations/Version20180530031926.php index d4133297..69db324c 100644 --- a/Gemini/src/Migrations/Version20180530031926.php +++ b/Gemini/src/Migrations/Version20180530031926.php @@ -12,20 +12,40 @@ final class Version20180530031926 extends AbstractMigration { public function up(Schema $schema) { - // this up() migration is auto-generated, please modify it to your needs - $this->abortIf( - $this->connection->getDatabasePlatform()->getName() !== 'mysql', - 'Migration can only be executed safely on \'mysql\'.' - ); + $this->addSql( + 'DROP TABLE IF EXISTS Gemini;' + ); + if ('mysql' == $this->connection->getDatabasePlatform()->getName()) { + $this->addSql( + 'CREATE TABLE Gemini (fedora_hash VARCHAR(128) NOT NULL, + drupal_hash VARCHAR(128) NOT NULL, uuid VARCHAR(36) NOT NULL, + drupal_uri LONGTEXT NOT NULL, fedora_uri LONGTEXT NOT NULL, + dateCreated DATETIME NOT NULL, dateUpdated DATETIME NOT NULL, + UNIQUE KEY(fedora_hash, drupal_hash), PRIMARY KEY(uuid)) + DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB' + ); + } + elseif + ('postgresql' == $this->connection->getDatabasePlatform()->getName()) { + $this->addSql( + 'CREATE TABLE Gemini ( + fedora_hash VARCHAR(128) NOT NULL, + drupal_hash VARCHAR(128) NOT NULL, + uuid VARCHAR(36) PRIMARY KEY, + drupal_uri TEXT NOT NULL, + fedora_uri TEXT NOT NULL, + dateCreated TIMESTAMP NOT NULL, + dateUpdated TIMESTAMP NOT NULL + );' + ); $this->addSql( - 'CREATE TABLE Gemini (fedora_hash VARCHAR(128) NOT NULL, - drupal_hash VARCHAR(128) NOT NULL, uuid VARCHAR(36) NOT NULL, - drupal_uri LONGTEXT NOT NULL, fedora_uri LONGTEXT NOT NULL, - dateCreated DATETIME NOT NULL, dateUpdated DATETIME NOT NULL, - UNIQUE KEY(fedora_hash, drupal_hash), PRIMARY KEY(uuid)) - DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB' + 'CREATE UNIQUE INDEX fedora_drupal_hash ON Gemini (fedora_hash, drupal_hash);' ); + } + else { + $this->abortIf(TRUE, "Only MySQL/MariaDB and PostgreSQL are supported."); + } } public function down(Schema $schema)