Add ExportGeneration entity and migration

Introduce the `ExportGeneration` entity for managing export generation data, including related properties such as `exportAlias`, `options`, and `deleteAt`. Add corresponding database migration to create the `chill_main_export_generation` table with necessary constraints and indices. Update `composer.json` to include the `symfony/uid` package.
This commit is contained in:
Julien Fastré 2025-02-19 14:15:13 +01:00
parent 350661a4fa
commit cb068cdee7
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,93 @@
<?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\MainBundle\Entity;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* Contains the single execution of an export.
*
* Attached to a stored object, which will contains the result of the execution. The status of the stored object
* is the status of the export generation.
*
* Generated exports should be deleted after a certain time, given by the column `deletedAt`. The stored object can be
* deleted after the export generation removal.
*/
#[ORM\Entity()]
#[ORM\Table('chill_main_export_generation')]
class ExportGeneration implements TrackCreationInterface
{
use TrackCreationTrait;
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private UuidInterface $id;
#[ORM\ManyToOne(targetEntity: StoredObject::class, cascade: ['persist', 'refresh'])]
#[ORM\JoinColumn(nullable: false)]
private StoredObject $storedObject;
public function __construct(
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])]
private string $exportAlias,
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]'])]
private array $options = [],
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $deleteAt = null,
) {
$this->id = Uuid::uuid4();
$this->storedObject = new StoredObject(StoredObject::STATUS_PENDING);
}
public function setDeleteAt(?\DateTimeImmutable $deleteAt): ExportGeneration
{
$this->deleteAt = $deleteAt;
return $this;
}
public function getDeleteAt(): ?\DateTimeImmutable
{
return $this->deleteAt;
}
public function getId(): UuidInterface
{
return $this->id;
}
public function getStoredObject(): StoredObject
{
return $this->storedObject;
}
public function getExportAlias(): string
{
return $this->exportAlias;
}
public function getOptions(): array
{
return $this->options;
}
public static function fromSavedExport(SavedExport $savedExport, null|\DateTimeImmutable $deletedAt = null): self
{
return new self($savedExport->getExportAlias(), $savedExport->getOptions(), $deletedAt);
}
}

View File

@ -0,0 +1,40 @@
<?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 Version20250219130532 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a table for storing export generation';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE chill_main_export_generation (id UUID NOT NULL, deleteAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, exportAlias TEXT DEFAULT \'\' NOT NULL, options JSON DEFAULT \'[]\' NOT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, storedObject_id INT NOT NULL, createdBy_id INT DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_E644B77D6C99C13A ON chill_main_export_generation (storedObject_id)');
$this->addSql('CREATE INDEX IDX_E644B77D3174800F ON chill_main_export_generation (createdBy_id)');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.deleteAt IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.createdAt IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77D6C99C13A FOREIGN KEY (storedObject_id) REFERENCES chill_doc.stored_object (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77D3174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE chill_main_export_generation');
}
}