feat: 支持批量上传关卡

This commit is contained in:
richarjiang
2026-05-01 08:44:56 +08:00
parent f3f27def2b
commit 66a9ee2950
27 changed files with 5262 additions and 515 deletions

View File

@@ -0,0 +1,34 @@
/**
* 一次性脚本:给所有已有关卡回填 sortKey。
*
* 前置prisma schema 已加 sortKey 字段,并已跑过 `pnpm run db:push`。
* 执行pnpm tsx prisma/backfill-sort-keys.ts
*/
import { PrismaClient } from '@prisma/client'
import { generateKeyBetween } from 'fractional-indexing'
async function main() {
const db = new PrismaClient()
try {
const levels = await db.level.findMany({
orderBy: [{ sortOrder: 'asc' }, { createdAt: 'asc' }],
select: { id: true },
})
let prev: string | null = null
for (const { id } of levels) {
const key = generateKeyBetween(prev, null)
await db.level.update({ where: { id }, data: { sortKey: key } })
prev = key
}
// eslint-disable-next-line no-console
console.log(`backfilled ${levels.length} rows`)
} finally {
await db.$disconnect()
}
}
main().catch((e) => {
// eslint-disable-next-line no-console
console.error(e)
process.exit(1)
})