
CREATE TABLE poteau_history (
    id INT PRIMARY KEY,
    fabrication_id INT,
    NbPoteau INT,
    HauteurPoteau DECIMAL(10,2),
    PrixPoteau DECIMAL(10,2),
    Platine TINYINT,
    created_at DATETIME,
    updated_at DATETIME
);

INSERT INTO poteau_history (
    id,
    fabrication_id,
    NbPoteau,
    HauteurPoteau,
    PrixPoteau,
    Platine,
    created_at,
    updated_at
)
SELECT 
    ROW_NUMBER() OVER (ORDER BY p.IDPROCESS ASC) AS id,
    p.IDPROCESS AS fabrication_id,
    f.NbPoteau,
    f.HauteurPoteau,
    f.PrixPoteau,
    f.Platine,
    p.D_Fabrication AS created_at,
    p.D_Modification AS updated_at
FROM temp_process AS p
INNER JOIN temp_fabrications AS f 
    ON p.IDFABRICATION = f.IDFABRICATION
WHERE 
       f.NbPoteau <> 0 
    OR f.HauteurPoteau <> 0 
    OR f.PrixPoteau <> 0 
    OR f.Platine <> 0
ORDER BY p.IDPROCESS ASC;
