From dce3ceda407fc6eae5f450412d605f8145accbf5 Mon Sep 17 00:00:00 2001 From: Georgi Kolev Date: Fri, 2 Feb 2024 19:12:20 +0200 Subject: [PATCH 1/2] Migrate doctrine mappings from xml to php attributes - Make fk int - Add indexes for searching by logged_at and fk. --- src/DataDogAuditBundle.php | 3 +-- src/Entity/Association.php | 17 ++++++++++++++-- src/Entity/AuditLog.php | 18 +++++++++++++++++ .../config/doctrine/Association.orm.xml | 16 --------------- .../config/doctrine/AuditLog.orm.xml | 20 ------------------- 5 files changed, 34 insertions(+), 40 deletions(-) delete mode 100644 src/Resources/config/doctrine/Association.orm.xml delete mode 100644 src/Resources/config/doctrine/AuditLog.orm.xml diff --git a/src/DataDogAuditBundle.php b/src/DataDogAuditBundle.php index 6456932..53db9d1 100644 --- a/src/DataDogAuditBundle.php +++ b/src/DataDogAuditBundle.php @@ -13,9 +13,8 @@ public function build(ContainerBuilder $container): void parent::build($container); if (class_exists(DoctrineOrmMappingsPass::class)) { - $namespaces = [__DIR__.'/Resources/config/doctrine' => 'DataDog\\AuditBundle\\Entity']; $container->addCompilerPass( - DoctrineOrmMappingsPass::createXmlMappingDriver($namespaces) + DoctrineOrmMappingsPass::createAttributeMappingDriver(['DataDog\\AuditBundle\\Entity'], [__DIR__.'/Entity']) ); } } diff --git a/src/Entity/Association.php b/src/Entity/Association.php index 6f29272..4f53c2f 100644 --- a/src/Entity/Association.php +++ b/src/Entity/Association.php @@ -2,18 +2,31 @@ namespace DataDog\AuditBundle\Entity; +use Doctrine\ORM\Mapping as ORM; + +#[ORM\Entity] +#[ORM\Table(name: 'audit_associations')] +#[ORM\Index(columns: ['fk'])] class Association { + #[ORM\Column(type: 'bigint', options: ['unsigned' => true])] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] private ?int $id; + #[ORM\Column(length: 128)] private string $typ; + #[ORM\Column(length: 128, nullable: true)] private ?string $tbl; + #[ORM\Column(nullable: true)] private ?string $label; - private string $fk; + #[ORM\Column(type: 'integer', options: ['unsigned' => true])] + private int $fk; + #[ORM\Column] private string $class; public function getId(): ?int @@ -43,7 +56,7 @@ public function getLabel(): ?string return $this->label; } - public function getFk(): string + public function getFk(): int { return $this->fk; } diff --git a/src/Entity/AuditLog.php b/src/Entity/AuditLog.php index e019cd3..b8f8d04 100644 --- a/src/Entity/AuditLog.php +++ b/src/Entity/AuditLog.php @@ -2,22 +2,40 @@ namespace DataDog\AuditBundle\Entity; +use Doctrine\ORM\Mapping as ORM; + +#[ORM\Entity] +#[ORM\Table(name: 'audit_logs')] +#[ORM\Index(columns: ['logged_at'])] class AuditLog { + #[ORM\Column(type: 'bigint', options: ['unsigned' => true])] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] private ?int $id; + #[ORM\Column(length: 12)] private string $action; + #[ORM\Column(length: 128)] private string $tbl; + #[ORM\OneToOne(targetEntity: Association::class)] + #[ORM\JoinColumn(unique: true, nullable: false)] private Association $source; + #[ORM\OneToOne(targetEntity: Association::class)] + #[ORM\JoinColumn(unique: true)] private ?Association $target; + #[ORM\OneToOne(targetEntity: Association::class)] + #[ORM\JoinColumn(unique: true)] private ?Association $blame; + #[ORM\Column(type: 'json', nullable: true)] private ?array $diff; + #[ORM\Column(name: 'logged_at', type: 'datetime')] private \DateTimeInterface $loggedAt; public function getId(): ?int diff --git a/src/Resources/config/doctrine/Association.orm.xml b/src/Resources/config/doctrine/Association.orm.xml deleted file mode 100644 index fce2631..0000000 --- a/src/Resources/config/doctrine/Association.orm.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/Resources/config/doctrine/AuditLog.orm.xml b/src/Resources/config/doctrine/AuditLog.orm.xml deleted file mode 100644 index d2c2df7..0000000 --- a/src/Resources/config/doctrine/AuditLog.orm.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - From 72c391bd668fb344568e8995aa83b836c4f49e56 Mon Sep 17 00:00:00 2001 From: Georgi Kolev Date: Fri, 2 Feb 2024 19:46:11 +0200 Subject: [PATCH 2/2] closes #87 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ec69d3a..f3c687c 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "require": { "php": ">=8.0", "doctrine/dbal": "^2.9|^3.1.4", - "doctrine/doctrine-bundle": "^2.2", - "doctrine/orm": "^2.6", + "doctrine/doctrine-bundle": "^2.9", + "doctrine/orm": "^2.9", "symfony/security-bundle": "^5.4|^6.0", "symfony/framework-bundle": "^5.4|^6.0" },