Repair the 2026-07-30 review findings #1

Merged
kami merged 15 commits from repair/review-2026-07-30 into master 2026-07-30 22:48:15 +02:00
3 changed files with 29 additions and 11 deletions
Showing only changes of commit cd46ac397f - Show all commits
+8 -3
View File
1
@@ -1147,9 +1147,14 @@ export class DbService {
async createArtist(data: Artist): Promise<Artist> {
const res = await this.pgClient.query(
`INSERT INTO artists (name, mbid, discogs_id, image_path)
VALUES (normalize_artist($1), $2, $3, $4) RETURNING *`,
[data.name, data.mbid, data.discogs_id, data.image_path]
// `canonical_name` is NOT NULL with no default, so omitting it fails on a
// fresh volume (the live DB's column predates the constraint). It holds the
// DISPLAY name: the raw input, not normalize_artist()'s output, which
// truncates on `/` and a standalone `x` ("AC/DC" -> "AC"). Matches the
// convention in workers' scanner.service.resolveOrCreateArtist.
`INSERT INTO artists (name, canonical_name, mbid, discogs_id, image_path)
VALUES (normalize_artist($1), $2, $3, $4, $5) RETURNING *`,
[data.name, data.name?.trim() || data.name, data.mbid, data.discogs_id, data.image_path]
);
return res.rows[0];
}
+11 -6
View File
@@ -330,14 +330,17 @@ export class EnrichmentService {
const sortName = mbArtist.sortName || this.generateSortName(canonicalName);
const newArtist = await this.pgClient.query(
`INSERT INTO artists (name, canonical_name, sort_name, mbid, normalized_name)
VALUES ($1, $2, $3, $4, $5)
// normalized_name is a GENERATED ALWAYS column in schema.sql
// (normalize_artist(name)); writing to it explicitly errors with
// 428C9 on any database built from schema.sql. Let Postgres derive it.
`INSERT INTO artists (name, canonical_name, sort_name, mbid)
VALUES ($1, $2, $3, $4)
ON CONFLICT (mbid) DO UPDATE SET
canonical_name = EXCLUDED.canonical_name,
sort_name = EXCLUDED.sort_name,
name = EXCLUDED.name
RETURNING id`,
[rawArtistName, canonicalName, sortName, mbArtist.artistMbid, normalized]
[rawArtistName, canonicalName, sortName, mbArtist.artistMbid]
);
const artistId = newArtist.rows[0].id;
@@ -371,10 +374,12 @@ export class EnrichmentService {
const sortName = this.generateSortName(rawName);
const result = await this.pgClient.query(
`INSERT INTO artists (name, canonical_name, sort_name, normalized_name)
VALUES ($1, $2, $3, $4)
// normalized_name is GENERATED ALWAYS (normalize_artist(name)) in
// schema.sql — inserting it explicitly fails with 428C9. Derived by PG.
`INSERT INTO artists (name, canonical_name, sort_name)
VALUES ($1, $2, $3)
RETURNING id`,
[rawName, rawName, sortName, normalized]
[rawName, rawName, sortName]
);
const artistId = result.rows[0].id;
+10 -2
View File
@@ -237,9 +237,17 @@ export class ScannerService {
return { id: String(found.rows[0].id), name: String(found.rows[0].name) };
}
// `canonical_name` is NOT NULL in schema.sql with no default, so it MUST be
// supplied here — omitting it makes every artist insert fail on a fresh
// volume (and processFile swallows the error, so the scan silently yields an
// empty library). It holds the DISPLAY name: we store the raw tag name, not
// the normalize_artist() output, because that function truncates on `/` and
// a standalone `x` ("AC/DC" -> "AC", "Felix Mendelssohn" -> "Feli"). The
// enrichment path later overwrites canonical_name with the MusicBrainz name;
// until then the raw tag is the most faithful display value we have.
const inserted = await this.pgClient.query(
'INSERT INTO artists (name) VALUES ($1) RETURNING id, name',
[name]
'INSERT INTO artists (name, canonical_name) VALUES ($1, $2) RETURNING id, name',
[name, rawName.trim() || name]
);
return { id: String(inserted.rows[0].id), name: String(inserted.rows[0].name) };
}