Browse Source

优化迁移sql:
1.function get_data_migration_offset,传入表名,当前id,返回对应偏移量。

xxy 6 years ago
parent
commit
6c4e85f9d0

+ 50 - 0
TRS.WCM.Developer/贵州项目/1_get_data_migration_offset.sql

@@ -0,0 +1,50 @@
+DROP FUNCTION IF EXISTS get_data_migration_offset;
+DELIMITER $$
+CREATE FUNCTION get_data_migration_offset(table_name VARCHAR(100), p_id BIGINT(20),cur_offset INT(11))
+  RETURNS INT(255)
+  BEGIN
+    DECLARE x INT (11) DEFAULT 0;
+		IF table_name = 'wcmdocument' THEN
+			SET  x = IFNULL((SELECT offset from document_offset WHERE p_id > previous_id ORDER BY OFFSET desc limit 1),0);
+			IF x = 0 THEN
+				SET x = cur_offset;
+			END IF;
+			RETURN x;
+		END IF;
+		IF table_name = 'wcmchannel' THEN
+			SET  x = IFNULL((SELECT offset from channel_offset WHERE p_id > previous_id ORDER BY OFFSET desc limit 1),0);
+			IF x = 0 THEN
+				SET x = cur_offset;
+			END IF;
+			RETURN x;
+		END IF;
+		IF table_name = 'wcmwebsite' THEN
+			SET  x = IFNULL((SELECT offset from site_offset WHERE p_id > previous_id ORDER BY OFFSET desc limit 1),0);
+			IF x = 0 THEN
+				SET x = cur_offset;
+			END IF;
+			RETURN x;
+		END IF;
+		IF table_name = 'wcmtemplate' THEN
+			SET  x = IFNULL((SELECT offset from template_offset WHERE p_id > previous_id ORDER BY OFFSET desc limit 1),0);
+			IF x = 0 THEN
+				SET x = cur_offset;
+			END IF;
+			RETURN x;
+		END IF;
+		IF table_name = 'xwcmtableinfo' THEN
+			SET  x = IFNULL((SELECT offset from tableinfo_offset WHERE p_id > previous_id ORDER BY OFFSET desc limit 1),0);
+			IF x = 0 THEN
+				SET x = cur_offset;
+			END IF;
+			RETURN x;
+		END IF;
+		IF table_name = 'xwcmviewinfo' THEN
+			SET  x = IFNULL((SELECT offset from viewInfo_offset WHERE p_id > previous_id ORDER BY OFFSET desc limit 1),0);
+			IF x = 0 THEN
+				SET x = cur_offset;
+			END IF;
+			RETURN x;
+		END IF;
+		RETURN -1;
+  END $$

+ 1 - 1
TRS.WCM.Developer/贵州项目/2.sp_data_migration_buildOffset.sql

@@ -7,7 +7,7 @@ CREATE PROCEDURE sp_data_migration_buildOffset(IN n SMALLINT(2))
   BEGIN
 -- 文档表
     set @offset = IFNULL((select `offset` from document_offset where `times` = n),0);
-    IF @docOffset = 0 THEN
+    IF @offset = 0 THEN
 			SET @previous_id = IFNULL((select MAX(docId) from wcmdocument),0);
 			SET @offset = IFNULL((select MAX(docid) from trs_hycloud_iip.wcmdocument),0);
 			INSERT INTO document_offset values(n,@previous_id,@offset);