Files
MemeStudio/prisma/rebalance-sort-keys.ts
2026-05-01 08:44:56 +08:00

27 lines
832 B
TypeScript
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.
/**
* 一次性脚本:把所有关卡的 sortKey 重新分配成 a... 递增序列,
* 消除历史上因"插到头部"产生的 Z 系列 key。
*
* 背景MySQL 默认 collation 大小写不敏感,把 `Zz` 和 `zz` 视作相等,
* 这会和 fractional-indexing 的字节序排序冲突。虽然应用层已切到 JS 排序,
* 运行一次这个脚本可以让 DB 数据和 JS 排序"视觉上"也一致,方便排查。
*
* 运行pnpm tsx prisma/rebalance-sort-keys.ts
*/
import { rebalanceAllKeys } from '../lib/sort-key'
import { prisma } from '../lib/prisma'
async function main() {
const count = await rebalanceAllKeys()
console.log(`rebalanced ${count} levels`)
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})