Skip to content

Commit

Permalink
add postgresql migration (#47)
Browse files Browse the repository at this point in the history
* add postgresql migration

* abort gemini table migration if db is not supported
  • Loading branch information
seth-shaw-unlv authored and dannylamb committed Jun 6, 2018
1 parent ac3ac50 commit ed840f7
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions Gemini/src/Migrations/Version20180530031926.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ed840f7

Please sign in to comment.