Add association between ExportGeneration and SavedExport

This update introduces a relationship between ExportGeneration and SavedExport. It includes a new SavedExport field in the ExportGeneration entity and the corresponding database migration. These changes enable ExportGeneration to reference its originating SavedExport if applicable.
This commit is contained in:
Julien Fastré 2025-03-13 18:05:34 +01:00
parent c9c29b9105
commit 39f60b5b34
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 47 additions and 1 deletions

View File

@ -49,6 +49,9 @@ class ExportGeneration implements TrackCreationInterface
private array $options = [], private array $options = [],
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $deleteAt = null, private ?\DateTimeImmutable $deleteAt = null,
#[ORM\ManyToOne(targetEntity: SavedExport::class)]
#[ORM\JoinColumn(nullable: true)]
private ?SavedExport $savedExport = null,
) { ) {
$this->id = Uuid::uuid4(); $this->id = Uuid::uuid4();
$this->storedObject = new StoredObject(StoredObject::STATUS_PENDING); $this->storedObject = new StoredObject(StoredObject::STATUS_PENDING);
@ -86,8 +89,13 @@ class ExportGeneration implements TrackCreationInterface
return $this->options; return $this->options;
} }
public function getSavedExport(): ?SavedExport
{
return $this->savedExport;
}
public static function fromSavedExport(SavedExport $savedExport, ?\DateTimeImmutable $deletedAt = null): self public static function fromSavedExport(SavedExport $savedExport, ?\DateTimeImmutable $deletedAt = null): self
{ {
return new self($savedExport->getExportAlias(), $savedExport->getOptions(), $deletedAt); return new self($savedExport->getExportAlias(), $savedExport->getOptions(), $deletedAt, $savedExport);
} }
} }

View File

@ -0,0 +1,38 @@
<?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\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250313165611 extends AbstractMigration
{
public function getDescription(): string
{
return 'Associate an export generation with eventual saved export';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_export_generation ADD savedExport_id UUID DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.savedExport_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77DA61D6F69 FOREIGN KEY (savedExport_id) REFERENCES chill_main_saved_export (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_E644B77DA61D6F69 ON chill_main_export_generation (savedExport_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_export_generation DROP CONSTRAINT FK_E644B77DA61D6F69');
$this->addSql('DROP INDEX IDX_E644B77DA61D6F69');
$this->addSql('ALTER TABLE chill_main_export_generation DROP savedExport_id');
}
}