-- =============================================================
-- Transfer data from kms_homol (legacy) → kms_new (Laravel)
-- Run as root on kms-laravel-mysql-1
-- =============================================================

SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

-- -----------------------------------------------------------
-- 1. WRR_Users → wrr_users (column rename mapping)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`wrr_users`;
INSERT INTO `kms_new`.`wrr_users` (Id, Login, password, LongName, Name, Tel, Auth, Email)
SELECT USERS_ID, LOGINNAME, PASSWORD, USERS_NAME, USERS_NAME, PHONENUMBER, AUTH, EMAIL
FROM `kms_homol`.`WRR_Users`;
SELECT CONCAT('wrr_users: ', COUNT(*), ' rows') AS status FROM `kms_new`.`wrr_users`;

-- -----------------------------------------------------------
-- 2. WRR_Modules → wrr_modules (column rename mapping)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`wrr_modules`;
INSERT INTO `kms_new`.`wrr_modules` (Id, ShortName, LongName, SortOrder)
SELECT MODULES_ID, MODULES_SHORTNAME, MODULES_NAME, DISPLAYORDER
FROM `kms_homol`.`WRR_Modules`;
SELECT CONCAT('wrr_modules: ', COUNT(*), ' rows') AS status FROM `kms_new`.`wrr_modules`;

-- -----------------------------------------------------------
-- 3. WRR_Params → wrr_params (column rename mapping)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`wrr_params`;
INSERT INTO `kms_new`.`wrr_params` (ParamName, ParamValue, Description)
SELECT PARAM, VALUE, DESCRIPTION
FROM `kms_homol`.`WRR_Params`;
SELECT CONCAT('wrr_params: ', COUNT(*), ' rows') AS status FROM `kms_new`.`wrr_params`;

-- -----------------------------------------------------------
-- 4. WRR_AdminMenu → wrr_admin_menu (column rename mapping)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`wrr_admin_menu`;
INSERT INTO `kms_new`.`wrr_admin_menu` (ViewCode, ViewName, FirstMenu, SortOrder)
SELECT View_Code, Menu, Father, Menu_Order
FROM `kms_homol`.`WRR_AdminMenu`;
SELECT CONCAT('wrr_admin_menu: ', COUNT(*), ' rows') AS status FROM `kms_new`.`wrr_admin_menu`;

-- -----------------------------------------------------------
-- 5. WRR_PrefViews → wrr_pref_views (column rename mapping)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`wrr_pref_views`;
INSERT INTO `kms_new`.`wrr_pref_views` (Id, ViewCode, ViewName, SortOrder)
SELECT VIEWS_ID, VIEWS_SHORTNAME, VIEWS_NAME, 0
FROM `kms_homol`.`WRR_PrefViews`;
SELECT CONCAT('wrr_pref_views: ', COUNT(*), ' rows') AS status FROM `kms_new`.`wrr_pref_views`;

-- -----------------------------------------------------------
-- 6. WRR_PrefReports → wrr_pref_reports (column rename mapping)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`wrr_pref_reports`;
INSERT INTO `kms_new`.`wrr_pref_reports` (Id, ShortName, LongName, FileName, ClassName)
SELECT REPORTS_ID, REPORTS_SHORTNAME, REPORTS_NAME, REPORTS_FILE, CLASSNAME
FROM `kms_homol`.`WRR_PrefReports`;
SELECT CONCAT('wrr_pref_reports: ', COUNT(*), ' rows') AS status FROM `kms_new`.`wrr_pref_reports`;

-- -----------------------------------------------------------
-- 7. KMS_Country → kms_country (shared columns)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_country`;
INSERT INTO `kms_new`.`kms_country` (`Id`, `Lieu`, `Country`, `ShortNotes`)
SELECT `Id`, `Lieu`, `Country`, `ShortNotes` FROM `kms_homol`.`KMS_Country`;
SELECT CONCAT('kms_country: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_country`;

-- -----------------------------------------------------------
-- 8. KMS_Dico → kms_dico (shared columns)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_dico`;
INSERT INTO `kms_new`.`kms_dico` (`Id`, `Name`)
SELECT `Id`, `Name` FROM `kms_homol`.`KMS_Dico`;
SELECT CONCAT('kms_dico: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_dico`;

-- -----------------------------------------------------------
-- 9. KMS_DicoAdj → kms_dico_adj (map columns + fix negatives)
-- Legacy: Id, KMS_Dico_Id, Value (=Adjective), Sens (=Sentiment), Type, Word
-- New:    Id, KMS_Dico_Id, Word, Adjective, Sentiment, KMS_DicoAdjGroup_Id, SubMenu
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_dico_adj`;
INSERT INTO `kms_new`.`kms_dico_adj` (Id, KMS_Dico_Id, Word, Adjective, Sentiment)
SELECT Id,
       CASE WHEN KMS_Dico_Id < 0 THEN NULL ELSE KMS_Dico_Id END,
       Word, Value, Sens
FROM `kms_homol`.`KMS_DicoAdj`;
SELECT CONCAT('kms_dico_adj: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_dico_adj`;

-- -----------------------------------------------------------
-- 10. KMS_DicoAdjGroup → kms_dico_adj_group (map columns)
-- Legacy: Id, KMS_Dico_Id, WordOrig, WordGroup
-- New:    Id, Name, SortOrder
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_dico_adj_group`;
INSERT INTO `kms_new`.`kms_dico_adj_group` (Id, Name, SortOrder)
SELECT Id, WordGroup, 0
FROM `kms_homol`.`KMS_DicoAdjGroup`;
SELECT CONCAT('kms_dico_adj_group: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_dico_adj_group`;

-- -----------------------------------------------------------
-- 11. KMS_Product → kms_product (shared columns)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_product`;
INSERT INTO `kms_new`.`kms_product` (`Id`, `Code`, `Name`, `ClientName`, `Color`, `Type`, `KMS_Dico_Id`)
SELECT `Id`, `Code`, `Name`, `ComName`, `Color`, `ProductType`, `KMS_Dico_Id`
FROM `kms_homol`.`KMS_Product`;
SELECT CONCAT('kms_product: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_product`;

-- -----------------------------------------------------------
-- 12. KMS_Study → kms_study (shared columns — many product/quanti columns)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_study`;
INSERT INTO `kms_new`.`kms_study` (
  Id, Code, Name, ClientName, StartDate, EndDate,
  KMS_Product_Id_11, KMS_Product_Id_12, KMS_Product_Id_13, KMS_Product_Id_14,
  KMS_Product_Id_15, KMS_Product_Id_16, KMS_Product_Id_17, KMS_Product_Id_18,
  KMS_Product_Id_19,
  KMS_Product_Id_21, KMS_Product_Id_22, KMS_Product_Id_23, KMS_Product_Id_24,
  KMS_Product_Id_25, KMS_Product_Id_26, KMS_Product_Id_27, KMS_Product_Id_28,
  KMS_Product_Id_29,
  KMS_Product_Id_31, KMS_Product_Id_32, KMS_Product_Id_33, KMS_Product_Id_34,
  KMS_Product_Id_35, KMS_Product_Id_36, KMS_Product_Id_37, KMS_Product_Id_38,
  KMS_Product_Id_39,
  KMS_Product_Id_41, KMS_Product_Id_42, KMS_Product_Id_43, KMS_Product_Id_44,
  KMS_Product_Id_45, KMS_Product_Id_46, KMS_Product_Id_47, KMS_Product_Id_48,
  KMS_Product_Id_49,
  KMS_Product_Id_51, KMS_Product_Id_52, KMS_Product_Id_53, KMS_Product_Id_54,
  KMS_Product_Id_55, KMS_Product_Id_56, KMS_Product_Id_57, KMS_Product_Id_58,
  KMS_Product_Id_59,
  Sexe, Age_From, Age_To, Lieu,
  Quan_01_Str, Quan_01_Order, Quan_02_Str, Quan_02_Order,
  Quan_03_Str, Quan_03_Order, Quan_04_Str, Quan_04_Order,
  Quan_05_Str, Quan_05_Order, Quan_06_Str, Quan_06_Order,
  Quan_07_Str, Quan_07_Order, Quan_08_Str, Quan_08_Order,
  Quan_09_Str, Quan_09_Order, Quan_10_Str, Quan_10_Order,
  Quan_11_Str, Quan_11_Order, Quan_12_Str, Quan_12_Order,
  Quan_13_Str, Quan_13_Order, Quan_14_Str, Quan_14_Order,
  Quan_15_Str, Quan_15_Order, Quan_16_Str, Quan_16_Order,
  Quan_17_Str, Quan_17_Order, Quan_18_Str, Quan_18_Order,
  Quan_19_Str, Quan_19_Order, Quan_20_Str, Quan_20_Order,
  Quan_21_Str, Quan_21_Order, Quan_22_Str, Quan_22_Order,
  Portrait_Product1, Portrait_Product2, Portrait_Product3, Portrait_Product4, Portrait_Product5,
  Quan_Order_Product1, Quan_Order_Product2, Quan_Order_Product3, Quan_Order_Product4, Quan_Order_Product5,
  KMS_Dico_Id, KMS_Product_Id_P1, KMS_Product_Id_P2, KMS_Product_Id_P3, KMS_Product_Id_P4, KMS_Product_Id_P5,
  KMS_Study_Id_Phase2, DownloadKey
)
SELECT
  Id, Code, Name, ClientName, StartDate, EndDate,
  KMS_Product_Id_11, KMS_Product_Id_12, KMS_Product_Id_13, KMS_Product_Id_14,
  KMS_Product_Id_15, KMS_Product_Id_16, KMS_Product_Id_17, KMS_Product_Id_18,
  KMS_Product_Id_19,
  KMS_Product_Id_21, KMS_Product_Id_22, KMS_Product_Id_23, KMS_Product_Id_24,
  KMS_Product_Id_25, KMS_Product_Id_26, KMS_Product_Id_27, KMS_Product_Id_28,
  KMS_Product_Id_29,
  KMS_Product_Id_31, KMS_Product_Id_32, KMS_Product_Id_33, KMS_Product_Id_34,
  KMS_Product_Id_35, KMS_Product_Id_36, KMS_Product_Id_37, KMS_Product_Id_38,
  KMS_Product_Id_39,
  KMS_Product_Id_41, KMS_Product_Id_42, KMS_Product_Id_43, KMS_Product_Id_44,
  KMS_Product_Id_45, KMS_Product_Id_46, KMS_Product_Id_47, KMS_Product_Id_48,
  KMS_Product_Id_49,
  KMS_Product_Id_51, KMS_Product_Id_52, KMS_Product_Id_53, KMS_Product_Id_54,
  KMS_Product_Id_55, KMS_Product_Id_56, KMS_Product_Id_57, KMS_Product_Id_58,
  KMS_Product_Id_59,
  Sexe, Age_From, Age_To, Lieu,
  Quan_01_Str, Quan_01_Order, Quan_02_Str, Quan_02_Order,
  Quan_03_Str, Quan_03_Order, Quan_04_Str, Quan_04_Order,
  Quan_05_Str, Quan_05_Order, Quan_06_Str, Quan_06_Order,
  Quan_07_Str, Quan_07_Order, Quan_08_Str, Quan_08_Order,
  Quan_09_Str, Quan_09_Order, Quan_10_Str, Quan_10_Order,
  Quan_11_Str, Quan_11_Order, Quan_12_Str, Quan_12_Order,
  Quan_13_Str, Quan_13_Order, Quan_14_Str, Quan_14_Order,
  Quan_15_Str, Quan_15_Order, Quan_16_Str, Quan_16_Order,
  Quan_17_Str, Quan_17_Order, Quan_18_Str, Quan_18_Order,
  Quan_19_Str, Quan_19_Order, Quan_20_Str, Quan_20_Order,
  Quan_21_Str, Quan_21_Order, Quan_22_Str, Quan_22_Order,
  Portrait_Product1, Portrait_Product2, Portrait_Product3, Portrait_Product4, Portrait_Product5,
  Quan_Order_Product1, Quan_Order_Product2, Quan_Order_Product3, Quan_Order_Product4, Quan_Order_Product5,
  KMS_Dico_Id, KMS_Product_Id_P1, KMS_Product_Id_P2, KMS_Product_Id_P3, KMS_Product_Id_P4, KMS_Product_Id_P5,
  KMS_Study_Id_Phase2, DownloadKey
FROM `kms_homol`.`KMS_Study`;
SELECT CONCAT('kms_study: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_study`;

-- -----------------------------------------------------------
-- 13. KMS_StudyAccess → kms_study_access (map USERS_ID → WRR_Users_Id)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_study_access`;
INSERT INTO `kms_new`.`kms_study_access` (KMS_Study_Id, WRR_Users_Id)
SELECT KMS_Study_Id, USERS_ID
FROM `kms_homol`.`KMS_StudyAccess`;
SELECT CONCAT('kms_study_access: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_study_access`;

-- -----------------------------------------------------------
-- 14. KMS_StudyOtherAttr → kms_study_other_attr (map columns)
-- Legacy: KMS_Study_Id, QuestOrder, Block, Question, QuestType, QuestLabel, CheckField, CheckOperator, CheckValue
-- New:    Id, KMS_Study_Id, QuestOrder, Block, Question, QuestType, QuestLabel, CheckMin, CheckMax, CheckList
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_study_other_attr`;
INSERT INTO `kms_new`.`kms_study_other_attr` (KMS_Study_Id, QuestOrder, Block, Question, QuestType, QuestLabel)
SELECT KMS_Study_Id, QuestOrder, Block, Question, QuestType, QuestLabel
FROM `kms_homol`.`KMS_StudyOtherAttr`;
SELECT CONCAT('kms_study_other_attr: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_study_other_attr`;

-- -----------------------------------------------------------
-- 15. KMS_Norme → kms_norme (shared columns)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_norme`;
INSERT INTO `kms_new`.`kms_norme` (`Id`, `Name`)
SELECT `Id`, `Name` FROM `kms_homol`.`KMS_Norme`;
SELECT CONCAT('kms_norme: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_norme`;

-- -----------------------------------------------------------
-- 16. KMS_NormeStudy → kms_norme_study (shared columns, no Id in legacy)
-- Legacy: KMS_Norme_Id, KMS_Study_Id, KMS_Product_Id
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_norme_study`;
INSERT INTO `kms_new`.`kms_norme_study` (KMS_Norme_Id, KMS_Study_Id, KMS_Product_Id)
SELECT KMS_Norme_Id, KMS_Study_Id, KMS_Product_Id
FROM `kms_homol`.`KMS_NormeStudy`;
SELECT CONCAT('kms_norme_study: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_norme_study`;

-- -----------------------------------------------------------
-- 17. KMS_Portrait → kms_portrait (shared columns)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_portrait`;
INSERT INTO `kms_new`.`kms_portrait` (`Id`, `Name`, `Code`, `SortOrder`)
SELECT `Id`, `Name`, `Code`, `OrderDef` FROM `kms_homol`.`KMS_Portrait`;
SELECT CONCAT('kms_portrait: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_portrait`;

-- -----------------------------------------------------------
-- 18. KMS_Quanti → kms_quanti (shared columns)
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_quanti`;
INSERT INTO `kms_new`.`kms_quanti` (`Id`, `Name`, `Code`)
SELECT `Id`, `Description`, `Code` FROM `kms_homol`.`KMS_Quanti`;
SELECT CONCAT('kms_quanti: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_quanti`;

-- -----------------------------------------------------------
-- 19. KMS_Interview → kms_interview (map columns)
-- Legacy: Id, KMS_Study_Id, Users_Id, Users_Id_Enq, ExtId, DateInterview, DateInput, Prenom, Sexe, Age, Lieu, KMS_Product_Id_B1..B5
-- New:    Id, KMS_Study_Id, Prenom, Sexe, Age, Lieu, NumeroEnq, DateEnq, Enqueteur
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_interview`;
INSERT INTO `kms_new`.`kms_interview` (Id, KMS_Study_Id, Prenom, Sexe, Age, Lieu, NumeroEnq, DateEnq)
SELECT Id, KMS_Study_Id, Prenom, Sexe, Age, Lieu, ExtId, DateInterview
FROM `kms_homol`.`KMS_Interview`;
SELECT CONCAT('kms_interview: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_interview`;

-- -----------------------------------------------------------
-- 20. KMS_InterviewOtherAttr → kms_interview_other_attr (map columns)
-- Legacy: KMS_Interview_Id, Block, Question, Answer
-- New:    Id, KMS_Interview_Id, KMS_StudyOtherAttr_Id, Value
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_interview_other_attr`;
INSERT INTO `kms_new`.`kms_interview_other_attr` (KMS_Interview_Id, Value)
SELECT KMS_Interview_Id, Answer
FROM `kms_homol`.`KMS_InterviewOtherAttr`;
SELECT CONCAT('kms_interview_other_attr: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_interview_other_attr`;

-- -----------------------------------------------------------
-- 21. KMS_Form → kms_form (shared columns — many adjective/quanti columns)
-- Legacy has FaitEvolPercMqText, new has FaitEvolPercText
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_form`;
INSERT INTO `kms_new`.`kms_form` (
  Id, KMS_Interview_Id, KMS_Product_Id, IsBest, NoteAppreciation,
  Adjectif_1, AdjectifSens_1, Adjectif_2, AdjectifSens_2,
  Adjectif_3, AdjectifSens_3, Adjectif_4, AdjectifSens_4,
  Adjectif_5, AdjectifSens_5, Adjectif_6, AdjectifSens_6,
  Adjectif_7, AdjectifSens_7, Adjectif_8, AdjectifSens_8,
  Adjectif_9, AdjectifSens_9, Adjectif_10, AdjectifSens_10,
  Like_1, Like_2, Like_3, Like_4, Like_5,
  Like_6, Like_7, Like_8, Like_9, Like_10,
  DisLike_1, DisLike_2, DisLike_3, DisLike_4, DisLike_5,
  DisLike_6, DisLike_7, DisLike_8, DisLike_9, DisLike_10,
  EssaiePeau,
  Quan_01, Quan_02, Quan_03, Quan_04, Quan_05,
  Quan_06, Quan_07, Quan_08, Quan_09, Quan_10,
  Quan_11, Quan_12, Quan_13, Quan_14, Quan_15,
  Quan_16, Quan_17, Quan_18, Quan_19, Quan_20,
  Quan_21, Quan_22,
  NoteSurPeau, FaitEvolPercMq, FaitEvolPercText,
  EssaieProduit, TelFixe, TelMobile, RappelJour, RappelHeure, FrequencePorte
)
SELECT
  Id, KMS_Interview_Id, KMS_Product_Id, IsBest, NoteAppreciation,
  Adjectif_1, AdjectifSens_1, Adjectif_2, AdjectifSens_2,
  Adjectif_3, AdjectifSens_3, Adjectif_4, AdjectifSens_4,
  Adjectif_5, AdjectifSens_5, Adjectif_6, AdjectifSens_6,
  Adjectif_7, AdjectifSens_7, Adjectif_8, AdjectifSens_8,
  Adjectif_9, AdjectifSens_9, Adjectif_10, AdjectifSens_10,
  Like_1, Like_2, Like_3, Like_4, Like_5,
  Like_6, Like_7, Like_8, Like_9, Like_10,
  DisLike_1, DisLike_2, DisLike_3, DisLike_4, DisLike_5,
  DisLike_6, DisLike_7, DisLike_8, DisLike_9, DisLike_10,
  EssaiePeau,
  Quan_01, Quan_02, Quan_03, Quan_04, Quan_05,
  Quan_06, Quan_07, Quan_08, Quan_09, Quan_10,
  Quan_11, Quan_12, Quan_13, Quan_14, Quan_15,
  Quan_16, Quan_17, Quan_18, Quan_19, Quan_20,
  Quan_21, Quan_22,
  NoteSurPeau, FaitEvolPercMq, FaitEvolPercMqText,
  EssaieProduit, TelFixe, TelMobile, RappelJour, RappelHeure, FrequencePorte
FROM `kms_homol`.`KMS_Form`;
SELECT CONCAT('kms_form: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_form`;

-- -----------------------------------------------------------
-- 22. KMS_FormAdjTbl → kms_form_adj_tbl (map columns)
-- Legacy: Id, KMS_Interview_Id, KMS_Product_Id, IsBest, NoteAppreciation, EssaiePeau, Type, Sens, Adjectif
-- New:    Id, KMS_Form_Id, KMS_Study_Id, KMS_Product_Id, Word, Adjective, Sentiment, Type
-- Map: Sens→Sentiment, Adjectif→Adjective
-- KMS_Form_Id and KMS_Study_Id not available in legacy — set NULL
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_form_adj_tbl`;
INSERT INTO `kms_new`.`kms_form_adj_tbl` (KMS_Product_Id, Adjective, Sentiment, Type)
SELECT KMS_Product_Id, Adjectif, Sens, Type
FROM `kms_homol`.`KMS_FormAdjTbl`;
SELECT CONCAT('kms_form_adj_tbl: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_form_adj_tbl`;

-- -----------------------------------------------------------
-- 23. KMS_FormNoteTbl → kms_form_note_tbl (map columns)
-- Legacy: Id, KMS_Interview_Id, KMS_Product_Id, IsBest, NoteAppreciation, EssaiePeau, Quan, Note
-- New:    Id, KMS_Form_Id, KMS_Study_Id, KMS_Product_Id, NoteName, NoteValue
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_form_note_tbl`;
INSERT INTO `kms_new`.`kms_form_note_tbl` (KMS_Product_Id, NoteName, NoteValue)
SELECT KMS_Product_Id, Quan, Note
FROM `kms_homol`.`KMS_FormNoteTbl`;
SELECT CONCAT('kms_form_note_tbl: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_form_note_tbl`;

-- -----------------------------------------------------------
-- 24. KMS_FormPortrait → kms_form_portrait (map columns)
-- Legacy: KMS_Form_Id, ChineType, Value  (no Id column)
-- New:    Id, KMS_Form_Id, Type, Value
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_form_portrait`;
INSERT INTO `kms_new`.`kms_form_portrait` (KMS_Form_Id, Type, Value)
SELECT KMS_Form_Id, ChineType, Value
FROM `kms_homol`.`KMS_FormPortrait`;
SELECT CONCAT('kms_form_portrait: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_form_portrait`;

-- -----------------------------------------------------------
-- 25. KMS_FormChine → kms_form_chine (map columns)
-- Legacy: KMS_Form_Id, ChineType, ChineCot, Value  (no Id, no CotationType)
-- New:    Id, KMS_Form_Id, Type, Value, CotationType, Cotation
-- -----------------------------------------------------------
TRUNCATE TABLE `kms_new`.`kms_form_chine`;
INSERT INTO `kms_new`.`kms_form_chine` (KMS_Form_Id, Type, Value, Cotation)
SELECT KMS_Form_Id, ChineType, Value, ChineCot
FROM `kms_homol`.`KMS_FormChine`;
SELECT CONCAT('kms_form_chine: ', COUNT(*), ' rows') AS status FROM `kms_new`.`kms_form_chine`;

-- -----------------------------------------------------------
-- Re-enable FK checks
-- -----------------------------------------------------------

SELECT '=== Transfer complete ===' AS status;
