2.sp_data_migration_buildOffset.sql 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. use trs_data_migration;
  2. -- 迁移前执行call sp_data_migration_buildOffset(n);
  3. -- 为偏移量记录表插入数据。
  4. DROP PROCEDURE IF EXISTS sp_data_migration_buildOffset;
  5. DELIMITER $$
  6. CREATE PROCEDURE sp_data_migration_buildOffset(IN n SMALLINT(2))
  7. BEGIN
  8. -- 文档表
  9. set @offset = IFNULL((select `offset` from document_offset where `times` = n),0);
  10. IF @offset = 0 THEN
  11. SET @previous_id = IFNULL((select MAX(docId) from wcmdocument),0);
  12. SET @offset = IFNULL((select MAX(docid) from trs_hycloud_iip.wcmdocument),0);
  13. INSERT INTO document_offset values(n,@previous_id,@offset);
  14. END IF;
  15. -- 站点表
  16. set @offset = IFNULL((select `offset` from site_offset where `times` = n),0);
  17. IF @offset = 0 THEN
  18. SET @previous_id = IFNULL((select MAX(siteId) from wcmwebsite),0);
  19. SET @offset = IFNULL((select MAX(siteId) from trs_hycloud_iip.wcmwebsite),0);
  20. INSERT INTO site_offset values(n,@previous_id,@offset);
  21. END IF;
  22. -- 栏目表
  23. set @offset = IFNULL((select `offset` from channel_offset where `times` = n),0);
  24. IF @offset = 0 THEN
  25. SET @previous_id = IFNULL((select MAX(channelId) from wcmchannel),0);
  26. SET @offset = IFNULL((select MAX(channelId) from trs_hycloud_iip.wcmchannel),0);
  27. INSERT INTO channel_offset values(n,@previous_id,@offset);
  28. END IF;
  29. -- template表
  30. set @offset = IFNULL((select `offset` from template_offset where `times` = n),0);
  31. IF @offset = 0 THEN
  32. SET @previous_id = IFNULL((select MAX(tempId) from wcmtemplate),0);
  33. SET @offset = IFNULL((select MAX(tempId) from trs_hycloud_iip.wcmtemplate),0);
  34. INSERT INTO template_offset values(n,@previous_id,@offset);
  35. END IF;
  36. -- viewInfo表
  37. set @offset = IFNULL((select `offset` from viewInfo_offset where `times` = n),0);
  38. IF @offset = 0 THEN
  39. SET @previous_id = IFNULL((select MAX(viewInfoId) from xwcmviewinfo),0);
  40. SET @offset = IFNULL((select MAX(viewInfoId) from trs_hycloud_iip.xwcmviewinfo),0);
  41. INSERT INTO viewInfo_offset values(n,@previous_id,@offset);
  42. END IF;
  43. -- tableInfo表
  44. set @offset = IFNULL((select `offset` from tableInfo_offset where `times` = n),0);
  45. IF @offset = 0 THEN
  46. SET @previous_id = IFNULL((select MAX(tableInfoId) from xwcmtableinfo),0);
  47. SET @offset = IFNULL((select MAX(tableInfoId) from trs_hycloud_iip.xwcmtableinfo),0);
  48. INSERT INTO tableInfo_offset values(n,@previous_id,@offset);
  49. END IF;
  50. END $$
  51. DELIMITER ;