mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-02-26 10:10:02 +00:00
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:
87
src/Bundle/ChillMainBundle/Entity/AuditTrail.php
Normal file
87
src/Bundle/ChillMainBundle/Entity/AuditTrail.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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 Version20260123162433 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create table chill_main_audit_trail';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user