- 内容底座改为你提供的语法体系(入门/基础/进阶 69 知识点,中文讲解 + 中英对照例句 + 六步教学法),整体更适合小学生 - 内容存库(grammar_point),家长中心新增"编辑英语课程"可改标题/目标/ 课文,保存即时生效 - 取消顺序解锁,所有课程可直接学习,通过测验即点亮 - 测验引擎支持 选择/判断/填空/连词成句/连线 五种题型,达标自动联动 当日英语打卡 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
// 将参考语法体系(ref-data.json)灌入 grammar_point 表;仅当表为空时执行
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { sql } from "drizzle-orm";
|
|
import { drizzle } from "drizzle-orm/mysql2";
|
|
import mysql from "mysql2/promise";
|
|
import { grammarPoints } from "../src/db/schema";
|
|
|
|
type RefPoint = {
|
|
id: string;
|
|
title: string;
|
|
difficulty: number;
|
|
prereq: string[];
|
|
summary: string;
|
|
md: string;
|
|
};
|
|
type RefLevel = { id: string; name: string; points: RefPoint[] };
|
|
|
|
async function main() {
|
|
const file = path.join(process.cwd(), "src/content/grammar/ref-data.json");
|
|
const data = JSON.parse(fs.readFileSync(file, "utf8")) as { levels: RefLevel[] };
|
|
const conn = await mysql.createConnection(process.env.DATABASE_URL!);
|
|
const db = drizzle(conn);
|
|
|
|
const [cnt] = await db.select({ n: sql<number>`COUNT(*)` }).from(grammarPoints);
|
|
if (cnt.n > 0) {
|
|
console.log("grammar_point 已有", cnt.n, "条,跳过种子");
|
|
await conn.end();
|
|
return;
|
|
}
|
|
|
|
let seq = 0;
|
|
const rows = [];
|
|
for (const lvl of data.levels) {
|
|
for (const p of lvl.points) {
|
|
seq += 1;
|
|
rows.push({
|
|
pointId: p.id,
|
|
level: lvl.id,
|
|
levelName: lvl.name,
|
|
title: p.title,
|
|
difficulty: p.difficulty,
|
|
summary: p.summary,
|
|
prereq: JSON.stringify(p.prereq ?? []),
|
|
md: p.md,
|
|
seq,
|
|
});
|
|
}
|
|
}
|
|
await db.insert(grammarPoints).values(rows);
|
|
console.log("已写入 grammar_point:", rows.length, "条");
|
|
await conn.end();
|
|
}
|
|
|
|
main();
|