Skip to content

Commit

Permalink
Merge pull request #22 from dmstr/feature/postgres-support
Browse files Browse the repository at this point in the history
Added support for postgres db
  • Loading branch information
schmunk42 authored Aug 19, 2021
2 parents 7a41708 + 84f4940 commit 7a1c452
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
23 changes: 18 additions & 5 deletions src/migrations/m180119_151608_add_initial_publication_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class m180119_151608_add_initial_publication_tables extends Migration
*/
public function safeUp()
{
$tableOptions = $this->db->getDriverName() === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci' : null;

$this->createTable('{{%dmstr_publication_category}}', [
'id' => $this->primaryKey(),
'content_widget_template_id' => $this->integer()->notNull(),
'teaser_widget_template_id' => $this->integer()->notNull(),
'created_at' => $this->integer(),
'updated_at' => $this->integer()
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
], $tableOptions);
$this->addForeignKey('FK_category_hrzg_widget_template0', '{{%dmstr_publication_category}}', 'content_widget_template_id', '{{%hrzg_widget_template}}', 'id');
$this->addForeignKey('FK_category_hrzg_widget_template1', '{{%dmstr_publication_category}}', 'teaser_widget_template_id', '{{%hrzg_widget_template}}', 'id');

Expand All @@ -29,7 +31,7 @@ public function safeUp()
'title' => $this->string(80)->null(),
'created_at' => $this->integer(),
'updated_at' => $this->integer()
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
], $tableOptions);
$this->addForeignKey('FK_category_translation_category_translation0', '{{%dmstr_publication_category_translation}}', 'category_id', '{{%dmstr_publication_category}}', 'id', 'CASCADE');

$this->createTable('{{%dmstr_publication_item}}', [
Expand All @@ -39,20 +41,31 @@ public function safeUp()
'end_date' => $this->dateTime(),
'created_at' => $this->integer(),
'updated_at' => $this->integer()
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
], $tableOptions);
$this->addForeignKey('FK_item_translation_category_translation0', '{{%dmstr_publication_item}}', 'category_id', '{{%dmstr_publication_category}}', 'id');


if ($this->db->getDriverName() === 'pgsql') {
$this->execute(<<<SQL
CREATE TYPE pit_status AS ENUM ('draft','published');
SQL
);
$enumColumnConfig = "pit_status default 'draft'";
} else {
$enumColumnConfig = "ENUM('draft', 'published') NOT NULL DEFAULT 'draft'";
}

$this->createTable('{{%dmstr_publication_item_translation}}', [
'id' => $this->primaryKey(),
'item_id' => $this->integer()->notNull(),
'language_code' => $this->string(8)->notNull(),
'title' => $this->string(80),
'content_widget_json' => $this->text(),
'teaser_widget_json' => $this->text(),
'status' => "ENUM('draft', 'published') NOT NULL DEFAULT 'draft'",
'status' => $enumColumnConfig,
'created_at' => $this->integer(),
'updated_at' => $this->integer()
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
], $tableOptions);
$this->addForeignKey('FK_item_translation_item0', '{{%dmstr_publication_item_translation}}', 'item_id', '{{%dmstr_publication_item}}', 'id', 'CASCADE');
}

Expand Down
16 changes: 14 additions & 2 deletions src/migrations/m180710_091658_add_meta_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,28 @@ class m180710_091658_add_meta_table extends Migration
*/
public function safeUp()
{
$tableOptions = $this->db->getDriverName() === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci' : null;

if ($this->db->getDriverName() === 'pgsql') {
$this->execute(<<<SQL
CREATE TYPE pim_status AS ENUM ('draft','published');
SQL
);
$enumColumnConfig = "pim_status default 'draft'";
} else {
$enumColumnConfig = "ENUM('draft', 'published') NOT NULL DEFAULT 'draft'";
}

$this->createTable('{{%dmstr_publication_item_meta}}', [
'id' => $this->primaryKey(),
'item_id' => $this->integer()->notNull(),
'language_code' => $this->string(8)->notNull(),
'status' => "ENUM('draft', 'published') NOT NULL DEFAULT 'draft'",
'status' => $enumColumnConfig,
'release_date' => $this->dateTime()->notNull(),
'end_date' => $this->dateTime(),
'created_at' => $this->integer(),
'updated_at' => $this->integer()
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
], $tableOptions);

$this->addForeignKey(
'fk_publication_translation_meta_id',
Expand Down
19 changes: 11 additions & 8 deletions src/migrations/m181031_131819_add_tag_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class m181031_131819_add_tag_tables extends Migration
*/
public function safeUp()
{
$tableOptions = $this->db->getDriverName() === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci' : null;

$this->createTable('{{%dmstr_publication_tag}}',
[
'id' => $this->primaryKey(),
Expand All @@ -27,23 +29,24 @@ public function safeUp()
'language' => $this->char(7)->notNull(),
'name' => $this->string(128)->notNull(),
'created_at' => $this->integer(),
'updated_at' => $this->integer(),
'UNIQUE KEY `UQ_item_language_name` (`tag_id`,`language`,`name`)',
'CONSTRAINT `FK_tag_translation0` FOREIGN KEY (`tag_id`) REFERENCES {{%dmstr_publication_tag}} (`id`)'
'updated_at' => $this->integer()
],
'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
$tableOptions);
$this->createIndex('UQ_item_language_name','{{%dmstr_publication_tag_translation}}', ['tag_id', 'language', 'name'], true);
$this->addForeignKey('FK_tag_translation0','{{%dmstr_publication_tag_translation}}', 'tag_id', '{{%dmstr_publication_tag}}', 'id');


$this->createTable('{{%dmstr_publication_tag_x_item}}',
[
'item_id' => $this->integer()->notNull(),
'tag_id' => $this->integer()->notNull(),
'created_at' => $this->integer(),
'updated_at' => $this->integer(),
'PRIMARY KEY (`item_id`,`tag_id`)',
'UNIQUE KEY `dmstr_tag_x_item_unique` (`item_id`,`tag_id`)',
'CONSTRAINT `fk_dmstr_tag_x_item0` FOREIGN KEY (`item_id`) REFERENCES {{%dmstr_publication_item}} (`id`) ON DELETE CASCADE ON UPDATE CASCADE',
'CONSTRAINT `fk_dmstr_tag_x_item1` FOREIGN KEY (`tag_id`) REFERENCES {{%dmstr_publication_tag}} (`id`) ON DELETE CASCADE ON UPDATE CASCADE'
'PRIMARY KEY (item_id, tag_id)'
]);
$this->addForeignKey('fk_dmstr_tag_x_item0','{{%dmstr_publication_tag_x_item}}', 'item_id', '{{%dmstr_publication_item}}', 'id','CASCADE', 'CASCADE');
$this->addForeignKey('fk_dmstr_tag_x_item1','{{%dmstr_publication_tag_x_item}}', 'tag_id', '{{%dmstr_publication_tag}}', 'id','CASCADE', 'CASCADE');

}

/**
Expand Down

0 comments on commit 7a1c452

Please sign in to comment.