릴리스: v1.4.30 로컬 DB 재초기화 및 legacy origin 자동 정리

This commit is contained in:
2026-04-02 21:32:14 +09:00
parent 9f6cb33bbd
commit 8898ac24f9
4 changed files with 44 additions and 0 deletions

View File

@@ -31,6 +31,20 @@ function serializeJson(value) {
return JSON.stringify(value || [])
}
function normalizeLegacyItemOrigins(items) {
let changed = false
const normalized = (items || []).map((item) => {
if (!item || typeof item !== 'object') return item
if (item.origin !== 'game') return item
changed = true
return {
...item,
origin: 'template',
}
})
return { normalized, changed }
}
function collectUploadSrcsFromItems(items, bucket) {
for (const item of items || []) {
if (typeof item?.src === 'string' && item.src.startsWith('/uploads/')) {
@@ -599,6 +613,25 @@ async function ensureSchema() {
async function ensureData() {
await ensureSchema()
const tierListRows = await query('SELECT id, pool_json FROM tierlists')
for (const row of tierListRows) {
const { normalized, changed } = normalizeLegacyItemOrigins(parseJson(row.pool_json, []))
if (!changed) continue
await query('UPDATE tierlists SET pool_json = ? WHERE id = ?', [serializeJson(normalized), row.id])
}
const requestRows = await query('SELECT id, items_json, board_items_json FROM template_requests')
for (const row of requestRows) {
const itemsResult = normalizeLegacyItemOrigins(parseJson(row.items_json, []))
const boardItemsResult = normalizeLegacyItemOrigins(parseJson(row.board_items_json, []))
if (!itemsResult.changed && !boardItemsResult.changed) continue
await query('UPDATE template_requests SET items_json = ?, board_items_json = ? WHERE id = ?', [
serializeJson(itemsResult.normalized),
serializeJson(boardItemsResult.normalized),
row.id,
])
}
}
async function countUsers() {