Skip to content

Commit 703b1a9

Browse files
committed
Removing unimportant constraint that causes trouble.
1 parent 3559872 commit 703b1a9

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

app/model/entity/ExerciseFileLink.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
* I.e., when Assignment is created from Exercise, the links are copied (immediately) as well.
1414
* The link of an exercise may be updated, but the link of an assignment is immutable.
1515
* @ORM\Entity
16-
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"key", "exercise_id"}),
17-
* @ORM\UniqueConstraint(columns={"key", "assignment_id"})})
16+
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"key", "exercise_id"})})
17+
*
18+
* Note: technically, there should be also unique constraint on (key, assignment_id); however, it causes more problems
19+
* than it solves. During sync operation, the assignment-related links are cleared and re-filled. Since the Doctrine
20+
* performs inserts before deletes, and we do not want to flush in the middle, it causes unique constraint violation.
1821
*/
1922
class ExerciseFileLink implements JsonSerializable
2023
{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20251214183529 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('DROP INDEX UNIQ_1187F7758A90ABA9D19302F8 ON exercise_file_link');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('CREATE UNIQUE INDEX UNIQ_1187F7758A90ABA9D19302F8 ON exercise_file_link (`key`, assignment_id)');
30+
}
31+
}

0 commit comments

Comments
 (0)