阶段性修改

This commit is contained in:
tianmo committed 2026-09-29 19:34:24 +08:00
1 parent 4833f7fa6a
commit 5a92bab835
65 files changed
+346 -178

No files matched your search

+15 -9
View File
@@ -18,10 +18,12 @@
import { PrismaClient } from '@prisma/client';
import { buildDataset } from './build';
import { loadLegacyDump, type LegacyRows } from './load';
import { loadLegacyDb } from './load-db';
import { ensureEnvLoaded, loadLegacyFromArgs } from './source';
import { SOURCE_LEGACY } from './transform';
// 必须在创建 PrismaClient 之前加载,否则读不到 DATABASE_URL
ensureEnvLoaded();
const prisma = new PrismaClient();
const flag = (name: string): boolean => process.argv.includes(`--${name}`);
@@ -46,19 +48,15 @@ const CLEAR_ORDER = [
async function main(): Promise<void> {
const dryRun = flag('dry-run');
const fromDb = flag('from-db');
const force = flag('force');
const staticBase = process.env.STATIC_BASE_URL ?? 'https://api.yeomai.site';
console.log('旧库 → 新库 数据迁移');
console.log(`数据源 : ${fromDb ? '直连旧库' : 'dump 文件'}`);
const { rows: db, label: sourceLabel } = await loadLegacyFromArgs(process.argv);
console.log(`数据源 : ${sourceLabel}`);
console.log(`域名改写 : api.yeomai.site → ${staticBase}`);
console.log(`模式 : ${dryRun ? '试运行(不写库)' : '正式写入'}\n`);
const db: LegacyRows = fromDb
? await loadLegacyDb(process.env.LEGACY_DATABASE_URL ?? '')
: loadLegacyDump();
const ds = buildDataset(db, staticBase);
const { diagnostics } = ds;
@@ -80,8 +78,17 @@ async function main(): Promise<void> {
const mapped = ds.homeCourses.filter((h) => h.course_id !== null).length;
console.log(`\n 首页长图已关联课程 ${mapped}/${ds.homeCourses.length}`);
console.log(` 非真实用户已过滤 ${diagnostics.skippedUsers.length}`);
console.log(` 孤儿权益已跳过 ${diagnostics.droppedEntitlements.length}`);
console.log(` 重复权益已跳过 ${diagnostics.duplicateEntitlements.length}`);
console.log(` 孤儿课时已跳过 ${diagnostics.skippedLessonOrphans.length}`);
if (diagnostics.skippedUsers.length > 0) {
console.log(
`\n ℹ 过滤说明:旧接口对 openid 无校验,用户表里混入了 ${diagnostics.skippedUsers.length} 条安全扫描探针记录`,
);
console.log(' (微信平台上架时的安全验证与公网扫描器都会产生这类记录),不是真实用户,因此不迁移。');
console.log(' 已确认所有购买记录都挂在真实用户上,不会丢课。');
}
if (diagnostics.unmappedHomeCourses.length > 0) {
console.log(` ⚠ 未关联课程的首页长图: ${diagnostics.unmappedHomeCourses.join('、')}`);
}
@@ -153,4 +160,3 @@ main()
process.exitCode = 1;
})
.finally(() => void prisma.$disconnect());