Skip to content

Commit 5755d40

Browse files
committed
Unique index on ShadowAssignmentPoints over awardee and shadowAssignment columns
1 parent b34898e commit 5755d40

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

app/model/entity/ShadowAssignmentPoints.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/**
1010
* @ORM\Entity
11+
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"shadow_assignment_id", "awardee_id"})})
1112
*
1213
* @method string getId()
1314
* @method string getNote()

app/model/repository/ShadowAssignmentPointsRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(EntityManager $em) {
2525
public function findPointsForAssignments(array $shadowAssignments, User $user): array {
2626
return $this->findBy([
2727
"author" => $user,
28-
"shadowAssignment" => $shadowAssignments,
28+
"shadowAssignment" => $shadowAssignments, // doctrine will handle given array with IN operator
2929
]);
3030
}
3131

fixtures/demo/30-shadowAssignments.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
App\Model\Entity\ShadowAssignment:
2-
demoShadowAssignment:
2+
"demoShadowAssignment{1..2}":
33
__construct:
44
createInGroup:
55
- @demoGroup
@@ -10,7 +10,7 @@ App\Model\Entity\ShadowAssignmentPoints:
1010
__construct:
1111
- 10
1212
- "Note"
13-
- @demoShadowAssignment
13+
- "@demoShadowAssignment<current()>"
1414
- @demoAdmin
1515
- @demoUser1
1616
- "<date()>"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Migrations;
4+
5+
use Doctrine\DBAL\Migrations\AbstractMigration;
6+
use Doctrine\DBAL\Schema\Schema;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs!
10+
*/
11+
class Version20180803193834 extends AbstractMigration
12+
{
13+
/**
14+
* @param Schema $schema
15+
*/
16+
public function up(Schema $schema)
17+
{
18+
// this up() migration is auto-generated, please modify it to your needs
19+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
20+
$this->addSql('CREATE UNIQUE INDEX UNIQ_AA4F8AFA806900AC79946661 ON shadow_assignment_points (shadow_assignment_id, awardee_id)');
21+
}
22+
23+
/**
24+
* @param Schema $schema
25+
*/
26+
public function down(Schema $schema)
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
30+
$this->addSql('DROP INDEX UNIQ_AA4F8AFA806900AC79946661 ON shadow_assignment_points');
31+
}
32+
}

0 commit comments

Comments
 (0)