diff --git a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml index 68353ee052..72615c3a5d 100644 --- a/src/bundle/Core/Resources/config/storage/legacy/schema.yaml +++ b/src/bundle/Core/Resources/config/storage/legacy/schema.yaml @@ -315,13 +315,14 @@ tables: ibexa_content_version: indexes: ibexa_content_version_status: { fields: [status] } - ibexa_content_version_idx_ver: { fields: [contentobject_id, version] } ibexa_content_version_idx_status: { fields: [contentobject_id, status] } ibexa_content_version_creator_id: { fields: [creator_id] } + uniqueConstraints: + ibexa_content_version_coid_version_unique: { fields: [contentobject_id, version] } id: id: { type: integer, nullable: false, options: { autoincrement: true } } fields: - contentobject_id: { type: integer, nullable: true } + contentobject_id: { type: integer, nullable: false } created: { type: integer, nullable: false, options: { default: '0' } } creator_id: { type: integer, nullable: false, options: { default: '0' } } initial_language_id: { type: bigint, nullable: false, options: { default: '0' } } diff --git a/tests/integration/Core/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php b/tests/integration/Core/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php new file mode 100644 index 0000000000..01628fdd26 --- /dev/null +++ b/tests/integration/Core/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php @@ -0,0 +1,75 @@ +get(DoctrineDatabase::class . '.inner'); + self::assertInstanceOf(DoctrineDatabase::class, $gateway); + + $this->gateway = $gateway; + } + + public function testInsertVersionThrowsOnDuplicateContentIdAndVersionNo(): void + { + $versionInfo = $this->getVersionInfoFixture(); + + self::assertGreaterThan(0, $this->gateway->insertVersion($versionInfo, [])); + + $this->expectException(UniqueConstraintViolationException::class); + $this->gateway->insertVersion($versionInfo, []); + } + + private function getVersionInfoFixture(): VersionInfo + { + $versionInfo = new VersionInfo(); + + $versionInfo->id = null; + $versionInfo->versionNo = self::VERSION_NO; + $versionInfo->creatorId = 14; + $versionInfo->status = VersionInfo::STATUS_DRAFT; + $versionInfo->creationDate = 1312278322; + $versionInfo->modificationDate = 1312278323; + $versionInfo->initialLanguageCode = 'eng-GB'; + $versionInfo->contentInfo = new ContentInfo( + [ + 'id' => self::CONTENT_ID, + 'alwaysAvailable' => true, + ] + ); + + return $versionInfo; + } +}