mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch '326-fix-document-page-acc-course' into 'master'
Add unique constraints to prevent person_document and accompanying_course document with the same object_id Closes #326 See merge request Chill-Projet/chill-bundles!759
This commit is contained in:
commit
39b918e7eb
@ -18,6 +18,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
|
|
||||||
#[ORM\Entity]
|
#[ORM\Entity]
|
||||||
#[ORM\Table('chill_doc.accompanyingcourse_document')]
|
#[ORM\Table('chill_doc.accompanyingcourse_document')]
|
||||||
|
#[ORM\UniqueConstraint(name: 'acc_course_document_unique_stored_object', columns: ['object_id'])]
|
||||||
class AccompanyingCourseDocument extends Document implements HasScopesInterface, HasCentersInterface
|
class AccompanyingCourseDocument extends Document implements HasScopesInterface, HasCentersInterface
|
||||||
{
|
{
|
||||||
#[ORM\ManyToOne(targetEntity: AccompanyingPeriod::class)]
|
#[ORM\ManyToOne(targetEntity: AccompanyingPeriod::class)]
|
||||||
|
@ -40,6 +40,7 @@ class Document implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
#[Assert\NotNull(message: 'Upload a document')]
|
#[Assert\NotNull(message: 'Upload a document')]
|
||||||
#[ORM\ManyToOne(targetEntity: StoredObject::class, cascade: ['persist'])]
|
#[ORM\ManyToOne(targetEntity: StoredObject::class, cascade: ['persist'])]
|
||||||
|
#[ORM\JoinColumn(name: 'object_id', referencedColumnName: 'id')]
|
||||||
private ?StoredObject $object = null;
|
private ?StoredObject $object = null;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: DocGeneratorTemplate::class)]
|
#[ORM\ManyToOne(targetEntity: DocGeneratorTemplate::class)]
|
||||||
|
@ -19,6 +19,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
|
|
||||||
#[ORM\Entity]
|
#[ORM\Entity]
|
||||||
#[ORM\Table('chill_doc.person_document')]
|
#[ORM\Table('chill_doc.person_document')]
|
||||||
|
#[ORM\UniqueConstraint(name: 'person_document_unique_stored_object', columns: ['object_id'])]
|
||||||
class PersonDocument extends Document implements HasCenterInterface, HasScopeInterface
|
class PersonDocument extends Document implements HasCenterInterface, HasScopeInterface
|
||||||
{
|
{
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\Migrations\DocStore;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20241118151618 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Force no duplicated object_id within person_document and accompanyingcourse_document';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
WITH ranked AS (
|
||||||
|
SELECT id, rank() OVER (PARTITION BY object_id ORDER BY id ASC) FROM chill_doc.accompanyingcourse_document
|
||||||
|
)
|
||||||
|
DELETE FROM chill_doc.accompanyingcourse_document WHERE id IN (SELECT id FROM ranked where "rank" <> 1)
|
||||||
|
SQL);
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX acc_course_document_unique_stored_object ON chill_doc.accompanyingcourse_document (object_id)');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX person_document_unique_stored_object ON chill_doc.person_document (object_id)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP INDEX acc_course_document_unique_stored_object');
|
||||||
|
$this->addSql('DROP INDEX person_document_unique_stored_object');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user