Add audit trail entity and migration

- Introduced `AuditTrail` entity to track user actions.
- Added Doctrine migration to create the `chill_main_audit_trail` table.
This commit is contained in:
2026-01-23 17:33:18 +01:00
parent e1b1f592fa
commit ed41224d7a
2 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
<?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 Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ORM\Table(name: 'chill_main_audit_trail')]
class AuditTrail
{
public function __construct(
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private UuidInterface $id,
#[ORM\Column(type: Types::STRING, length: 255)]
private string $action,
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
private \DateTimeImmutable $occurredAt,
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true)]
private ?User $user = null,
#[ORM\Column(type: Types::STRING, length: 255, nullable: false, options: ['default' => ''])]
private string $description = '',
/**
* @var list<array<string, mixed>>
*/
#[ORM\Column(type: Types::JSON, options: ['jsonb' => true, 'default' => "'[]'::jsonb"])]
private array $targets = [],
/**
* @var array<array-key, mixed>
*/
#[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<array<string, mixed>>
*/
public function getTargets(): array
{
return $this->targets;
}
/**
* @return array<array-key, mixed>
*/
public function getMetadata(): array
{
return $this->metadata;
}
}