feat : ajout d'un système de log pour les SUPER_ADMIN
This commit is contained in:
43
migrations/Version20260330120000.php
Normal file
43
migrations/Version20260330120000.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260330120000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create audit_logs table for tracking user actions.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE TABLE audit_logs (
|
||||
id SERIAL PRIMARY KEY,
|
||||
employee_id INTEGER DEFAULT NULL,
|
||||
username VARCHAR(180) NOT NULL,
|
||||
action VARCHAR(30) NOT NULL,
|
||||
entity_type VARCHAR(50) NOT NULL,
|
||||
entity_id INTEGER DEFAULT NULL,
|
||||
description TEXT NOT NULL,
|
||||
changes JSON DEFAULT NULL,
|
||||
affected_date DATE DEFAULT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
CONSTRAINT fk_audit_employee FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE SET NULL
|
||||
)');
|
||||
|
||||
$this->addSql('CREATE INDEX idx_audit_employee_created ON audit_logs (employee_id, created_at)');
|
||||
$this->addSql('CREATE INDEX idx_audit_entity ON audit_logs (entity_type, entity_id)');
|
||||
$this->addSql('CREATE INDEX idx_audit_created ON audit_logs (created_at)');
|
||||
$this->addSql('CREATE INDEX idx_audit_affected_date ON audit_logs (affected_date)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE audit_logs');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user