ALTER TABLE llx_prixmasse_hist ADD `fk_version2` INT DEFAULT '0' AFTER `rowid`;
ALTER TABLE llx_prixmassedet_hist ADD `fk_version2` INT DEFAULT '0' AFTER `rowid`;

UPDATE llx_prixmasse_hist pm LEFT JOIN llx_propale_history ph ON pm.fk_version = ph.rowid SET pm.fk_version2 = ph.fk_version;
UPDATE llx_prixmassedet_hist pm LEFT JOIN llx_propale_history ph ON pm.fk_version = ph.rowid SET pm.fk_version2 = ph.fk_version;

INSERT INTO llx_prixmasse (`fk_object`, `fk_version`, `fk_user_author`, `total_ht_before`, `percent`, `total_ht_after`, `datec`, `tms`, `entity`) SELECT `fk_object`, IFNULL(`fk_version2`, 0), `fk_user_author`, `total_ht_before`, `percent`, `total_ht_after`, `datec`, `tms`, `entity` FROM llx_prixmasse_hist;
INSERT INTO llx_prixmassedet (`fk_prixmasse`, `fk_version`, `fk_object`, `fk_objectdet`, `datec`, `tms`) SELECT `fk_prixmasse`, IFNULL(`fk_version2`, 0), `fk_object`, `fk_objectdet`, `datec`, `tms` FROM llx_prixmassedet_hist;

UPDATE llx_prixmasse p LEFT JOIN llx_propal_extrafields pe ON pe.fk_object = p.fk_object SET p.fk_version = IFNULL(pe.version_actuelle, 1) WHERE p.fk_version = 0;
UPDATE llx_prixmassedet pd LEFT JOIN llx_propal_extrafields pe ON pe.fk_object = pd.fk_object SET pd.fk_version = IFNULL(pe.version_actuelle, 1) WHERE pd.fk_version = 0;