Skip to content

Commit

Permalink
Merge pull request #3664 from MTES-MCT/feature/3650-timestampable-on-…
Browse files Browse the repository at this point in the history
…zone

[TECH] Ajout du trait TimestampableTrait sur la table zone
  • Loading branch information
numew authored Feb 5, 2025
2 parents 10d28ac + b86272d commit b827737
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions migrations/Version20250204095010.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20250204095010 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add created_at and updated_at fields on Zone';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE zone ADD created_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', ADD updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE type type VARCHAR(255) NOT NULL COMMENT \'Value possible enum ZoneType\'');
$this->addSql("
UPDATE zone z
INNER JOIN history_entry h ON z.id = h.entity_id
SET z.created_at = h.created_at
WHERE h.entity_name LIKE '%Zone'
AND h.event LIKE 'CREATE'
");
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE zone DROP created_at, DROP updated_at, CHANGE type type VARCHAR(255) DEFAULT \'AUTRE\' NOT NULL COMMENT \'Value possible enum ZoneType\'');
}
}
4 changes: 4 additions & 0 deletions src/Entity/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Entity;

use App\Entity\Behaviour\EntityHistoryInterface;
use App\Entity\Behaviour\TimestampableTrait;
use App\Entity\Enum\HistoryEntryEvent;
use App\Entity\Enum\ZoneType;
use App\Repository\ZoneRepository;
Expand All @@ -15,6 +16,7 @@
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: ZoneRepository::class)]
#[ORM\HasLifecycleCallbacks()]
#[ORM\UniqueConstraint(columns: ['name', 'territory_id'])]
#[UniqueEntity(
fields: ['name', 'territory'],
Expand All @@ -23,6 +25,8 @@
)]
class Zone implements EntityHistoryInterface
{
use TimestampableTrait;

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
Expand Down

0 comments on commit b827737

Please sign in to comment.