From 39f60b5b347a2eae7055174c840852153689dad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 13 Mar 2025 18:05:34 +0100 Subject: [PATCH] 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. --- .../Entity/ExportGeneration.php | 10 ++++- .../migrations/Version20250313165611.php | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20250313165611.php diff --git a/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php b/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php index 5e0465890..c06ea13a3 100644 --- a/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php +++ b/src/Bundle/ChillMainBundle/Entity/ExportGeneration.php @@ -49,6 +49,9 @@ class ExportGeneration implements TrackCreationInterface private array $options = [], #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)] private ?\DateTimeImmutable $deleteAt = null, + #[ORM\ManyToOne(targetEntity: SavedExport::class)] + #[ORM\JoinColumn(nullable: true)] + private ?SavedExport $savedExport = null, ) { $this->id = Uuid::uuid4(); $this->storedObject = new StoredObject(StoredObject::STATUS_PENDING); @@ -86,8 +89,13 @@ class ExportGeneration implements TrackCreationInterface return $this->options; } + public function getSavedExport(): ?SavedExport + { + return $this->savedExport; + } + 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); } } diff --git a/src/Bundle/ChillMainBundle/migrations/Version20250313165611.php b/src/Bundle/ChillMainBundle/migrations/Version20250313165611.php new file mode 100644 index 000000000..159f12b66 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20250313165611.php @@ -0,0 +1,38 @@ +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'); + } +}