릴리스: v1.4.31 legacy game 호환층 제거 마감
This commit is contained in:
@@ -9,7 +9,6 @@ const DB_PASSWORD = process.env.DB_PASSWORD || ''
|
||||
const DB_NAME = process.env.DB_NAME || 'tier_cursor'
|
||||
const DB_CONNECTION_LIMIT = process.env.DB_CONNECTION_LIMIT ? Number(process.env.DB_CONNECTION_LIMIT) : 10
|
||||
const FREEFORM_TOPIC_ID = 'freeform'
|
||||
const FREEFORM_GAME_ID = FREEFORM_TOPIC_ID
|
||||
|
||||
let poolPromise = null
|
||||
let initPromise = null
|
||||
@@ -31,20 +30,6 @@ 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/')) {
|
||||
@@ -284,10 +269,6 @@ async function closePool() {
|
||||
async function ensureSchema() {
|
||||
if (initPromise) return initPromise
|
||||
initPromise = (async () => {
|
||||
const legacyGamesExists = await tableExists('games')
|
||||
const legacyGameItemsExists = await tableExists('game_items')
|
||||
const legacyFavoriteGamesExists = await tableExists('favorite_games')
|
||||
|
||||
await query(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
@@ -322,14 +303,6 @@ async function ensureSchema() {
|
||||
await query('ALTER TABLE topics ADD COLUMN display_rank INT NULL DEFAULT NULL AFTER thumbnail_src')
|
||||
}
|
||||
|
||||
if (legacyGamesExists) {
|
||||
await query(`
|
||||
INSERT IGNORE INTO topics (id, name, thumbnail_src, is_public, display_rank, created_at)
|
||||
SELECT id, name, thumbnail_src, COALESCE(is_public, 1), display_rank, created_at
|
||||
FROM games
|
||||
`)
|
||||
}
|
||||
|
||||
await query(`
|
||||
CREATE TABLE IF NOT EXISTS topic_items (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
@@ -348,17 +321,6 @@ async function ensureSchema() {
|
||||
await query('ALTER TABLE topic_items ADD COLUMN display_order INT NULL DEFAULT NULL AFTER label')
|
||||
}
|
||||
|
||||
if (legacyGameItemsExists) {
|
||||
const legacyItemDisplayOrderColumns = await query("SHOW COLUMNS FROM game_items LIKE 'display_order'")
|
||||
await query(
|
||||
`
|
||||
INSERT IGNORE INTO topic_items (id, topic_id, src, label, display_order, created_at)
|
||||
SELECT id, game_id, src, label, ${legacyItemDisplayOrderColumns.length ? 'display_order' : 'NULL'}, created_at
|
||||
FROM game_items
|
||||
`
|
||||
)
|
||||
}
|
||||
|
||||
await query(`
|
||||
CREATE TABLE IF NOT EXISTS custom_items (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
@@ -421,14 +383,6 @@ async function ensureSchema() {
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
`)
|
||||
|
||||
if (legacyFavoriteGamesExists) {
|
||||
await query(`
|
||||
INSERT IGNORE INTO favorite_topics (user_id, topic_id, created_at)
|
||||
SELECT user_id, game_id, created_at
|
||||
FROM favorite_games
|
||||
`)
|
||||
}
|
||||
|
||||
await query(`
|
||||
CREATE TABLE IF NOT EXISTS image_assets (
|
||||
id VARCHAR(64) PRIMARY KEY,
|
||||
@@ -501,16 +455,10 @@ async function ensureSchema() {
|
||||
const hasSourceTopicId = await columnExists('template_requests', 'source_topic_id')
|
||||
if (!hasSourceTopicId) {
|
||||
await query("ALTER TABLE template_requests ADD COLUMN source_topic_id VARCHAR(120) NOT NULL DEFAULT 'freeform' AFTER source_tierlist_id")
|
||||
if (await columnExists('template_requests', 'source_game_id')) {
|
||||
await query('UPDATE template_requests SET source_topic_id = source_game_id WHERE source_topic_id = ?', [FREEFORM_TOPIC_ID])
|
||||
}
|
||||
}
|
||||
const hasTargetTopicId = await columnExists('template_requests', 'target_topic_id')
|
||||
if (!hasTargetTopicId) {
|
||||
await query("ALTER TABLE template_requests ADD COLUMN target_topic_id VARCHAR(120) NOT NULL DEFAULT '' AFTER source_topic_id")
|
||||
if (await columnExists('template_requests', 'target_game_id')) {
|
||||
await query("UPDATE template_requests SET target_topic_id = target_game_id WHERE target_topic_id = ''")
|
||||
}
|
||||
}
|
||||
const templateRequestStatusColumns = await query("SHOW COLUMNS FROM template_requests LIKE 'status'")
|
||||
if (!templateRequestStatusColumns.length) {
|
||||
@@ -536,9 +484,6 @@ async function ensureSchema() {
|
||||
const tierListTopicIdColumns = await query("SHOW COLUMNS FROM tierlists LIKE 'topic_id'")
|
||||
if (!tierListTopicIdColumns.length) {
|
||||
await query("ALTER TABLE tierlists ADD COLUMN topic_id VARCHAR(120) NOT NULL DEFAULT 'freeform' AFTER author_id")
|
||||
if (await columnExists('tierlists', 'game_id')) {
|
||||
await query('UPDATE tierlists SET topic_id = game_id WHERE topic_id = ?', [FREEFORM_TOPIC_ID])
|
||||
}
|
||||
}
|
||||
const tierListShowNamesColumns = await query("SHOW COLUMNS FROM tierlists LIKE 'show_character_names'")
|
||||
if (!tierListShowNamesColumns.length) {
|
||||
@@ -582,7 +527,7 @@ async function ensureSchema() {
|
||||
(?, ?, ?, ?),
|
||||
(?, ?, ?, ?)
|
||||
`,
|
||||
['example-game', '예시 게임', '', createdAt, 'another-game', '다른 예시 게임', '', createdAt]
|
||||
['example-topic', '예시 주제', '', createdAt, 'another-topic', '다른 예시 주제', '', createdAt]
|
||||
)
|
||||
|
||||
await query(
|
||||
@@ -594,12 +539,12 @@ async function ensureSchema() {
|
||||
`,
|
||||
[
|
||||
'img-1',
|
||||
'example-game',
|
||||
'example-topic',
|
||||
'/uploads/seeds/example1.png',
|
||||
'샘플 1',
|
||||
createdAt,
|
||||
'img-2',
|
||||
'example-game',
|
||||
'example-topic',
|
||||
'/uploads/seeds/example2.png',
|
||||
'샘플 2',
|
||||
createdAt,
|
||||
@@ -613,25 +558,6 @@ 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() {
|
||||
|
||||
@@ -24,7 +24,7 @@ const FREEFORM_TOPIC_ID = 'freeform'
|
||||
const FREEFORM_DEFAULT_TITLE = '직접 티어표 만들기'
|
||||
|
||||
function normalizePoolItem(item) {
|
||||
if (!item || !['game', 'template'].includes(item.origin) || typeof item.src !== 'string') return item
|
||||
if (!item || item.origin !== 'template' || typeof item.src !== 'string') return item
|
||||
if (item.src.startsWith('/uploads/')) return item
|
||||
|
||||
try {
|
||||
@@ -83,7 +83,7 @@ const templateRequestSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
src: z.string().min(1),
|
||||
label: z.string().min(1).max(60),
|
||||
origin: z.enum(['template', 'game', 'custom']).default('template'),
|
||||
origin: z.enum(['template', 'custom']).default('template'),
|
||||
})
|
||||
),
|
||||
})
|
||||
@@ -112,7 +112,7 @@ const tierListUpsertSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
src: z.string().min(1),
|
||||
label: z.string().min(1).max(60),
|
||||
origin: z.enum(['template', 'game', 'custom']).default('template'),
|
||||
origin: z.enum(['template', 'custom']).default('template'),
|
||||
})
|
||||
),
|
||||
}).superRefine((value, ctx) => {
|
||||
|
||||
Reference in New Issue
Block a user