
# 支持断点续迁，需要执行如下 sql

CREATE TABLE data_migration_log(
  table_name VARCHAR(100) NOT NULL COMMENT '迁移的表名',
  prev_id BIGINT(20) NOT NULL COMMENT '上一条数据ID',
  migration_time datetime NOT NULL default CURRENT_TIMESTAMP,
  PRIMARY KEY (table_name)
);

DROP FUNCTION IF EXISTS build_migration_log_sql;
DELIMITER $$
CREATE FUNCTION build_migration_log_sql(table_name VARCHAR(100), id BIGINT(20), curtime datetime)
  RETURNS VARCHAR(255)
  BEGIN
    DECLARE x VARCHAR(255) DEFAULT '';


    SET x =  concat('insert into ',
                    'data_migration_log (',
                    'table_name, ',
                    'prev_id,',
                    'migration_time',
                    ') ',
                    'values(',
                    '\'', table_name, '\',',
                    id, ',',
                    '\'', curtime, '\'',
                    ') ',
                    'on duplicate key update ',
                    'prev_id = ', id);
    RETURN x;
  END $$
