곡 합치기: 멜론 id가 없는 곡으로 합칠 때 UNIQUE 오류로 실패하던 것 수정(복사본에서 빼고 남는 곡으로 옮김). fix-text 중복 합치기가 운영에서 이걸로 막혔음(트랜잭션이라 바뀐 것 없음)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-19 22:42:23 +09:00
parent 8e6fd229da
commit 86bd2d8166
3 changed files with 12 additions and 3 deletions

View File

@@ -96,18 +96,19 @@ describe('admin songs', () => {
expect(bad.body.error).toContain('JSON');
});
test('duplicates are grouped by the normalized key and merged into one (sources, aliases, plays move over)', async () => {
test('duplicates are grouped by the normalized key and merged into one (sources, aliases, plays, Melon id move over)', async () => {
const { call } = await admin();
const cat = new Catalog(s.db);
const [a] = cat.upsert({ title: '광', artists: [{ name: 'SG워너비' }], source: 'sta', ref: '1' });
// a second row with the same key (an import that missed the match)
const b = Number(s.db.query("INSERT INTO songs (title, artist, match_key, created_at, updated_at, youtube_status, youtube_id, embeddable) VALUES ('광 (狂)', 'SG워너비', (SELECT match_key FROM songs WHERE id = ?), 0, 0, 'matched', 'VO88htcm09E', 1)").run(a!).lastInsertRowid);
s.db.query('UPDATE songs SET melon_id = 711627 WHERE id = ?').run(b);
s.db.query("INSERT INTO song_aliases (song_id, part, alias) VALUES (?, 'title', 'Crazy')").run(b);
const groups = (await call('/songs/duplicates')).body.groups;
expect(groups[0].songs.map((x: any) => x.id).sort()).toEqual([a, b].sort());
expect((await call('/songs/merge', { method: 'POST', body: JSON.stringify({ target: a, others: [b] }) })).body.merged).toBe(1);
const merged = (await call(`/songs/${a}`)).body;
expect(merged.song).toMatchObject({ youtube_id: 'VO88htcm09E', youtube_status: 'matched' });
expect(merged.song).toMatchObject({ youtube_id: 'VO88htcm09E', youtube_status: 'matched', melon_id: 711627 });
expect(merged.aliases.map((x: any) => x.alias)).toContain('Crazy');
expect((await call('/songs/duplicates')).body.groups).toEqual([]);
expect((await call('/songs?trash=1')).body.rows.map((r: any) => r.id)).toEqual([b]);