4_sp_city_n.sql 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. DROP PROCEDURE IF EXISTS sp_city_n;
  2. DELIMITER $$
  3. CREATE PROCEDURE sp_city_n(IN n INT)
  4. BEGIN
  5. # 每迁移一个wcm节点,@n 必须 +1
  6. SET @n = n;
  7. # 每个wcm节点,元数据表需要加上后缀,以区分同名元数据表
  8. SET @citySuffix = concat('_city', @n);
  9. # 支持断点续传,上一次迁移的最后一个 xx ID
  10. SET @prevSiteId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmwebsite'), 0);
  11. SET @prevChannelId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmchannel'), 0);
  12. SET @prevRecId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmchnldoc'), 0);
  13. SET @prevDocId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmdocument'), 0);
  14. SET @prevChannelSynId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmchannelsyn'), 0);
  15. SET @prevFolderPublishConfigId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmfolderpublishconfig'), 0);
  16. SET @prevTemplateId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmtemplate'), 0);
  17. SET @prevTemplateArgId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmtemplateargument'), 0);
  18. SET @prevTemplateEmployId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmtemplateemploy'), 0);
  19. SET @prevTemplateNestId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmtemplatenest'), 0);
  20. SET @prevTemplateQuoteId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmtemplatequote'), 0);
  21. SET @prevClassInfoId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmclassinfo'), 0);
  22. SET @prevClassInfoViewId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmclassinfoview'), 0);
  23. SET @prevFieldId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmdbfieldinfo'), 0);
  24. SET @prevMetaViewEmployerId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmmetaviewemployer'), 0);
  25. SET @prevTableInfoId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmtableinfo'), 0);
  26. SET @prevViewFieldInfoId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmviewfieldinfo'), 0);
  27. SET @prevViewId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmviewinfo'), 0);
  28. SET @prevMetaViewFieldGroupId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmmetaviewfieldgroup'), 0);
  29. # 支持数据增量 偏移量 修改
  30. # xx ID 偏移量,获取海云系统中的对应 xx maxID 错开一段距离,改为存入最大id
  31. SET @maxSiteId = IFNULL((SELECT MAX(siteId) from trs_hycloud_iip.wcmwebsite),0);
  32. SET @siteIdOffset = @maxSiteId - @prevSiteId;
  33. SET @maxChannelId= IFNULL((SELECT MAX(channelId) from trs_hycloud_iip.wcmchannel),0);
  34. SET @channelIdOffset = @maxChannelId - @prevChannelId;
  35. SET @maxRecId= IFNULL((SELECT MAX(recId) from trs_hycloud_iip.wcmchnldoc),0);
  36. SET @recIdOffset = @maxRecId - @prevRecId;
  37. SET @maxDocId= IFNULL((SELECT MAX(DOCID) from trs_hycloud_iip.wcmdocument),0);
  38. SET @docIdOffset = @maxDocId - @prevDocId;
  39. SET @maxViewId= IFNULL((SELECT MAX(viewInfoId) from trs_hycloud_iip.xwcmviewinfo),0);
  40. SET @viewIdOffset = @maxViewId - @prevViewId;
  41. SET @maxTableInfoId= IFNULL((SELECT MAX(TABLEINFOID) from trs_hycloud_iip.xwcmtableinfo),0);
  42. SET @tableInfoIdOffset = @maxTableInfoId - @prevTableInfoId;
  43. SET @maxFieldId = IFNULL((SELECT MAX(DBFIELDINFOID) from trs_hycloud_iip.xwcmdbfieldinfo),0);
  44. SET @fieldIdOffset = @maxFieldId - @prevFieldId;
  45. SET @maxChannelSynId= IFNULL((SELECT MAX(channelSynId) from trs_hycloud_iip.wcmchannelsyn),0);
  46. SET @channelSynIdOffset = @maxChannelSynId - @prevChannelSynId;
  47. SET @maxTemplateId = IFNULL((SELECT MAX(TEMPID) from trs_hycloud_iip.wcmtemplate),0);
  48. SET @templateIdOffset = @maxTemplateId - @prevTemplateId;
  49. SET @maxFolderPublishConfigId = IFNULL((SELECT MAX(FOLDERPUBLISHCONFIGID) from trs_hycloud_iip.wcmfolderpublishconfig),0);
  50. SET @folderPublishConfigIdOffset = @maxFolderPublishConfigId - @prevFolderPublishConfigId;
  51. SET @maxTemplateEmployId = IFNULL((SELECT MAX(TEMPLATEEMPLOYID) from trs_hycloud_iip.wcmtemplateemploy),0);
  52. SET @templateEmployIdOffset = @maxTemplateEmployId - @prevTemplateEmployId;
  53. SET @maxTemplateNestId= IFNULL((SELECT MAX(TEMPLATENESTID) from trs_hycloud_iip.wcmtemplatenest),0);
  54. SET @templateNestIdOffset = @maxTemplateNestId - @prevTemplateNestId;
  55. SET @maxTemplateQuoteId = IFNULL((SELECT MAX(TEMPLATEQUOTEID) from trs_hycloud_iip.wcmtemplatequote),0);
  56. SET @templateQuoteIdOffset = @maxTemplateQuoteId - @prevTemplateQuoteId;
  57. SET @maxMetaViewEmployerId = IFNULL((SELECT MAX(METAVIEWEMPLOYERID) from trs_hycloud_iip.xwcmmetaviewemployer),0);
  58. SET @metaViewEmployerIdOffset = @maxMetaViewEmployerId - @prevMetaViewEmployerId;
  59. SET @maxViewFieldInfoId = IFNULL((SELECT MAX(VIEWFIELDINFOID) from trs_hycloud_iip.xwcmviewfieldinfo),0);
  60. SET @viewFieldInfoIdOffset = @maxViewFieldInfoId - @prevViewFieldInfoId;
  61. SET @maxTemplateArgId= IFNULL((SELECT MAX(TEMPLATEARGUMENTID) from trs_hycloud_iip.wcmtemplateargument),0);
  62. SET @templateArgIdOffset = @maxTemplateArgId - @prevTemplateArgId;
  63. SET @maxClassInfoId = IFNULL((SELECT MAX(classInfoId) from trs_hycloud_iip.xwcmclassinfo),0);
  64. SET @classInfoIdOffset = @maxClassInfoId - @prevClassInfoId;
  65. SET @maxClassInfoViewId = IFNULL((SELECT MAX(CLASSINFOVIEWID) from trs_hycloud_iip.xwcmclassinfoview),0);
  66. SET @classInfoViewIdOffset = @maxClassInfoViewId - @prevClassInfoViewId;
  67. #基本信息迁移
  68. call sp_data_migration_wcmwebsite(@citySuffix, @prevSiteId, @siteIdOffset);
  69. call sp_data_migration_wcmchannel(@citySuffix, @prevChannelId, @siteIdOffset, @channelIdOffset);
  70. call sp_data_migration_wcmchannelsyn(@prevChannelSynId, @channelSynIdOffset, @channelIdOffset);
  71. call sp_data_migration_xwcmtableinfo(@citySuffix, @prevTableInfoId, @tableInfoIdOffset);
  72. call sp_data_migration_xwcmclassinfo(@prevClassInfoId, @classInfoIdOffset);
  73. call sp_data_migration_wcmtemplate(@prevTemplateId, @templateIdOffset, @siteIdOffset, @channelIdOffset);
  74. call sp_data_migration_wcmtemplatenest(@prevTemplateNestId, @templateNestIdOffset);
  75. call sp_data_migration_wcmfolderpublishconfig(@prevFolderPublishConfigId, @folderPublishConfigIdOffset, @siteIdOffset, @channelIdOffset);
  76. call sp_data_migration_wcmtemplateargument(@prevTemplateArgId, @templateArgIdOffset, @templateIdOffset, @siteIdOffset, @channelIdOffset);
  77. call sp_data_migration_wcmtemplateemploy(@prevTemplateEmployId, @templateEmployIdOffset, @templateIdOffset, @siteIdOffset, @channelIdOffset);
  78. call sp_data_migration_wcmtemplatequote(@prevTemplateQuoteId, @templateQuoteIdOffset, @templateIdOffset, @siteIdOffset, @channelIdOffset);
  79. call sp_data_migration_wcmchannelchildindexquote(@templateIdOffset, @siteIdOffset, @channelIdOffset);
  80. call sp_data_migration_xwcmviewinfo(@citySuffix, @prevViewId, @viewIdOffset, @tableInfoIdOffset);
  81. call sp_data_migration_xwcmdbfieldinfo(@citySuffix, @prevFieldId, @fieldIdOffset, @prevClassInfoId, @tableInfoIdOffset);
  82. call sp_data_migration_xwcmmetaviewemployer(@prevMetaViewEmployerId, @metaViewEmployerIdOffset, @viewIdOffset, @siteIdOffset, @channelIdOffset);
  83. call sp_data_migration_xwcmviewfieldinfo(@citySuffix, @prevViewFieldInfoId, @viewFieldInfoIdOffset, @tableInfoIdOffset, @prevClassInfoId, @dbFieldIdOffset, @metaViewFieldGroupIdOffset, @viewIdOffset, @viewIdOffset);
  84. #数据迁移
  85. call sp_data_migration_wcmdocument(@prevDocId, @docIdOffset, @viewIdOffset, @siteIdOffset, @channelIdOffset);
  86. call sp_data_migration_wcmchnldoc(@prevRecId, @recIdOffset, @docIdOffset, @siteIdOffset, @channelIdOffset, @viewIdOffset);
  87. call sp_data_migration_xwcmclassinfoview(@prevClassInfoViewId, @classInfoViewIdOffset, @classInfoIdOffset, @docIdOffset, @viewIdOffset);
  88. call sp_data_migration_wcmmetatable(@citySuffix, @prevTableInfoId, @prevDocId, @docIdOffset, @channelIdOffset);
  89. #附件迁移
  90. # 迁移 MAS 视频,6个wcm节点的视频是在一起的。可重复执行。
  91. # 支持断点续传,上一次迁移的最后一个 xx ID
  92. SET @prevMasId = ifnull((SELECT prev_id from data_migration_log where table_name = 'mas_masid'), 0);
  93. SET @prevMasVideoId = ifnull((SELECT prev_id from data_migration_log where table_name = 'mas_masvideo'), 0);
  94. SET @prevMaterialquoteId = ifnull((SELECT prev_id from data_migration_log where table_name = 'xwcmmaterial'), 0);
  95. SET @prevAppendixId = ifnull((SELECT prev_id from data_migration_log where table_name = 'wcmappendix'), 0);
  96. SET @maxMasId = IFNULL((SELECT MAX(ID) from trs_mas.mas_masid),0);
  97. SET @masIdOffset = @maxMasId - @prevMasId;
  98. SET @maxMasVideoId = IFNULL((SELECT MAX(ID) from trs_mas.mas_videostream),0);
  99. SET @masVideoIdOffset = @maxMasVideoId - @prevMasVideoId;
  100. SET @maxNAppendixId= IFNULL((SELECT MAX(appendixId) from trs_hycloud_iip.wcmappendix),0);
  101. SET @nappendixIdOffset = @maxNAppendixId - @prevMaterialquoteId;
  102. SET @maxAppendixId= IFNULL((SELECT MAX(appendixId) from trs_hycloud_iip.wcmappendix),0);
  103. SET @appendixIdOffset = @maxAppendixId - @prevAppendixId;
  104. call sp_data_migration_masid(@prevMasId, @masIdOffset);
  105. call sp_data_migration_masvideo(@prevMasVideoId, @masVideoIdOffset);
  106. #处理素材表
  107. call sp_data_migration_wcmappendix(@prevAppendixId, @appendixIdOffset, @docIdOffset);
  108. call sp_data_migration_xwcmmaterial(@prevMaterialquoteId, @nappendixIdOffset, @docIdOffset);
  109. END $$
  110. DELIMITER ;