Reply 表新增一列自增 ID
Closed this issue · 1 comments
sdjdd commented
为重构关键词搜索铺路,需要 Reply 表有个自增 ID 列。
添加步骤:
- 新增一列
nid
,设置为自增,初始值设置的大一点(至少要比目前 Reply 表的行数大) - 执行以下程序,为没有
nid
的行添加nid
:
let nextId = 1
const run = async () => {
const query = new AV.Query('Reply')
query.doesNotExist('nid')
query.ascending('createdAt')
query.limit(100)
try {
const replies = await query.find()
replies.forEach((reply) => reply.set('nid', nextId++))
await AV.Object.saveAll(replies)
setTimeout(run, 1000)
} catch (error) {
console.error({ nextId, error })
}
}
sdjdd commented
决定不这么实现