From ed41224d7a97dec9f443444b87e38aa3577c53b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 23 Jan 2026 17:33:18 +0100 Subject: [PATCH] Add audit trail entity and migration - Introduced `AuditTrail` entity to track user actions. - Added Doctrine migration to create the `chill_main_audit_trail` table. --- .../ChillMainBundle/Entity/AuditTrail.php | 87 +++++++++++++++++++ .../migrations/Version20260123162433.php | 38 ++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Entity/AuditTrail.php create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20260123162433.php diff --git a/src/Bundle/ChillMainBundle/Entity/AuditTrail.php b/src/Bundle/ChillMainBundle/Entity/AuditTrail.php new file mode 100644 index 000000000..814fb61b4 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/AuditTrail.php @@ -0,0 +1,87 @@ + ''])] + private string $description = '', + /** + * @var list> + */ + #[ORM\Column(type: Types::JSON, options: ['jsonb' => true, 'default' => "'[]'::jsonb"])] + private array $targets = [], + /** + * @var array + */ + #[ORM\Column(type: Types::JSON, options: ['jsonb' => true, 'default' => "'[]'::jsonb"])] + private array $metadata = [], + ) {} + + public function getId(): UuidInterface + { + return $this->id; + } + + public function getUser(): User + { + return $this->user; + } + + public function getOccurredAt(): \DateTimeImmutable + { + return $this->occurredAt; + } + + public function getAction(): string + { + return $this->action; + } + + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @return list> + */ + public function getTargets(): array + { + return $this->targets; + } + + /** + * @return array + */ + public function getMetadata(): array + { + return $this->metadata; + } +} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20260123162433.php b/src/Bundle/ChillMainBundle/migrations/Version20260123162433.php new file mode 100644 index 000000000..d49474615 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20260123162433.php @@ -0,0 +1,38 @@ +addSql("CREATE TABLE chill_main_audit_trail (id UUID NOT NULL, user_id INT DEFAULT NULL, action VARCHAR(255) NOT NULL, occurredAt TIMESTAMP(0) WITH TIME ZONE NOT NULL, description VARCHAR(255) DEFAULT '' NOT NULL, targets JSONB DEFAULT '[]'::jsonb NOT NULL, metadata JSONB DEFAULT '[]'::jsonb NOT NULL, PRIMARY KEY(id))"); + $this->addSql('CREATE INDEX IDX_331A47F4A76ED395 ON chill_main_audit_trail (user_id)'); + $this->addSql('COMMENT ON COLUMN chill_main_audit_trail.id IS \'(DC2Type:uuid)\''); + $this->addSql('COMMENT ON COLUMN chill_main_audit_trail.occurredAt IS \'(DC2Type:datetimetz_immutable)\''); + $this->addSql('ALTER TABLE chill_main_audit_trail ADD CONSTRAINT FK_331A47F4A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_audit_trail DROP CONSTRAINT FK_331A47F4A76ED395'); + $this->addSql('DROP TABLE chill_main_audit_trail'); + } +}