HaniBlindBox/server/scripts/migrate_users_data.sql
2026-01-02 05:18:05 +08:00

44 lines
1.9 KiB
Transact-SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================================
-- 用户数据迁移脚本
-- Feature: database-migration, Property 2: 数据记录数一致性
-- Feature: database-migration, Property 3: 时间戳转换正确性
-- Validates: Requirements 1.5, 1.6
-- ============================================================
USE honey_box;
GO
-- ============================================================
-- 1. users 表迁移
-- ============================================================
-- 源表: MySQL user (2,202 条记录)
-- 目标表: SQL Server users
-- 字段映射: openid->open_id, headimg->head_img, istest->is_test
-- 时间戳转换: DATEADD(SECOND, unix_timestamp, '1970-01-01')
-- 状态: 已完成 (72条样本数据已验证)
-- ============================================================
-- 2. user_accounts 表迁移
-- ============================================================
-- 源表: MySQL user_account (3,452 条记录)
-- 目标表: SQL Server user_accounts
-- 字段映射: 字段名保持一致
-- 时间戳转换: token_time, last_login_time (Unix时间戳 → DATETIME2)
-- 状态: 进行中
-- 迁移方法说明:
-- 1. 启用 IDENTITY_INSERT: SET IDENTITY_INSERT user_accounts ON;
-- 2. 批量插入数据每批50-100条
-- 3. 时间戳转换: DATEADD(SECOND, unix_timestamp, '1970-01-01')
-- 4. 完成后关闭: SET IDENTITY_INSERT user_accounts OFF;
-- 示例插入语句:
-- INSERT INTO user_accounts (id, user_id, account_token, token_num, token_time, last_login_time, last_login_ip, last_login_ip1, ip_adcode, ip_province, ip_city) VALUES
-- (id, user_id, N'token', N'token_num', DATEADD(SECOND, token_time, '1970-01-01'), DATEADD(SECOND, last_login_time, '1970-01-01'), N'ip', N'ip1', N'adcode', N'province', N'city');
-- 验证迁移后的记录数
SELECT 'users' as table_name, COUNT(*) AS migrated_count FROM users
UNION ALL
SELECT 'user_accounts' as table_name, COUNT(*) AS migrated_count FROM user_accounts;
GO