diff --git a/src/migrations/m180119_151608_add_initial_publication_tables.php b/src/migrations/m180119_151608_add_initial_publication_tables.php index 278ffb0..49be4fb 100644 --- a/src/migrations/m180119_151608_add_initial_publication_tables.php +++ b/src/migrations/m180119_151608_add_initial_publication_tables.php @@ -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'); @@ -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}}', [ @@ -39,9 +41,20 @@ 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(<<createTable('{{%dmstr_publication_item_translation}}', [ 'id' => $this->primaryKey(), 'item_id' => $this->integer()->notNull(), @@ -49,10 +62,10 @@ public function safeUp() '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'); } diff --git a/src/migrations/m180710_091658_add_meta_table.php b/src/migrations/m180710_091658_add_meta_table.php index fd6f045..952c88e 100644 --- a/src/migrations/m180710_091658_add_meta_table.php +++ b/src/migrations/m180710_091658_add_meta_table.php @@ -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(<<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', diff --git a/src/migrations/m181031_131819_add_tag_tables.php b/src/migrations/m181031_131819_add_tag_tables.php index 2af7af8..2741300 100644 --- a/src/migrations/m181031_131819_add_tag_tables.php +++ b/src/migrations/m181031_131819_add_tag_tables.php @@ -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(), @@ -27,11 +29,12 @@ 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}}', [ @@ -39,11 +42,11 @@ public function safeUp() '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'); + } /**