feat(normalization) : drop structure and productIds JSON columns

- Remove Composant.structure property, getter/setter
- Remove Piece.productIds property, setProductIds()
- Update fixtures to remove dropped columns
- Add migrations to drop both columns

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-13 08:19:54 +01:00
parent 8ed5f90b63
commit a6139d7090
8 changed files with 179 additions and 173 deletions

View File

@@ -67,10 +67,6 @@ class Composant
#[Groups(['composant:read'])]
private ?string $prix = null;
#[ORM\Column(type: Types::JSON, nullable: true)]
#[Groups(['composant:read'])]
private ?array $structure = null;
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'composants')]
#[ORM\JoinColumn(name: 'typeComposantId', referencedColumnName: 'id', nullable: true)]
#[Groups(['composant:read'])]
@@ -203,18 +199,6 @@ class Composant
return $this;
}
public function getStructure(): ?array
{
return $this->structure;
}
public function setStructure(?array $structure): static
{
$this->structure = $structure;
return $this;
}
public function getTypeComposant(): ?ModelType
{
return $this->typeComposant;

View File

@@ -79,10 +79,6 @@ class Piece
#[Groups(['piece:read'])]
private ?Product $product = null;
#[ORM\Column(type: Types::JSON, nullable: true, name: 'productIds')]
#[Groups(['piece:read'])]
private ?array $productIds = null;
/**
* @var Collection<int, Constructeur>
*/
@@ -214,15 +210,6 @@ class Piece
if (null !== $product) {
$this->addProduct($product);
if (empty($this->productIds)) {
$productId = $product->getId();
$this->productIds = $productId ? [$productId] : null;
}
}
if (!$product && empty($this->productIds)) {
$this->productIds = null;
}
return $this;
@@ -231,36 +218,12 @@ class Piece
/**
* @return string[]
*/
#[Groups(['piece:read'])]
public function getProductIds(): array
{
return $this->products->map(fn (Product $p) => $p->getId())->toArray();
}
public function setProductIds(?array $productIds): static
{
if (!is_array($productIds)) {
$this->productIds = null;
return $this;
}
$normalized = array_values(
array_unique(
array_filter(
array_map(
static fn ($value) => is_string($value) ? trim($value) : '',
$productIds,
),
static fn (string $value) => '' !== $value,
),
),
);
$this->productIds = [] === $normalized ? null : $normalized;
return $this;
}
/**
* @return Collection<int, Constructeur>
*/

View File

@@ -39,7 +39,6 @@ final class ComposantAuditSubscriber extends AbstractAuditSubscriber
'name' => $this->safeGet($entity, 'getName'),
'reference' => $this->safeGet($entity, 'getReference'),
'prix' => $this->safeGet($entity, 'getPrix'),
'structure' => $this->safeGet($entity, 'getStructure'),
'typeComposant' => $this->normalizeValue($this->safeGet($entity, 'getTypeComposant')),
'product' => $this->normalizeValue($this->safeGet($entity, 'getProduct')),
'constructeurIds' => $this->normalizeCollection($entity->getConstructeurs()),

View File

@@ -12,7 +12,7 @@ use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Events;
/**
* Keep the legacy single product relation in sync with the new productIds array.
* Keep the legacy single product relation in sync with the ManyToMany products collection.
*/
final class PieceProductSyncSubscriber implements EventSubscriber
{

View File

@@ -341,8 +341,8 @@ final class ModelTypeCategoryConversionService
{
// 1. Insert into pieces from composants
$count = $this->connection->executeStatement(
'INSERT INTO pieces (id, name, reference, prix, productids, typepieceid, productid, createdat, updatedat)
SELECT id, name, reference, prix, NULL, typecomposantid, productid, createdat, updatedat
'INSERT INTO pieces (id, name, reference, prix, typepieceid, productid, createdat, updatedat)
SELECT id, name, reference, prix, typecomposantid, productid, createdat, updatedat
FROM composants
WHERE typecomposantid = :id',
['id' => $modelTypeId],