From 6b71be428d9a08733fd5d85e724d7a977945d6e9 Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Thu, 5 Feb 2026 13:54:36 -0800 Subject: [PATCH] update amq schema to add some extra fields --- src/lib/db/client-db/seed.ts | 2 +- src/lib/db/import-amq.ts | 3 +++ src/lib/db/schema/index.ts | 26 ++++++++++++++++++++------ src/lib/types/amq/song.ts | 7 ++++--- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/lib/db/client-db/seed.ts b/src/lib/db/client-db/seed.ts index a5c8145..2b82fa8 100644 --- a/src/lib/db/client-db/seed.ts +++ b/src/lib/db/client-db/seed.ts @@ -14,7 +14,7 @@ import { getClientDb } from "$lib/db/client-db"; * This is intended for READ-ONLY browsing. Bump the version when you ship a new * snapshot so clients refresh. */ -export const AMQ_DB_SEED_VERSION = 1; +export const AMQ_DB_SEED_VERSION = 2; const SEED_ASSET_PATH = "/data/amq.sqlite"; const seededStorageKey = (version: number) => `amq.sqlocal.seeded.v${version}`; diff --git a/src/lib/db/import-amq.ts b/src/lib/db/import-amq.ts index 9592a0d..0dc7cc7 100644 --- a/src/lib/db/import-amq.ts +++ b/src/lib/db/import-amq.ts @@ -332,6 +332,9 @@ export async function importAmqData( name: s.name, category: s.category, fileName: s.fileName, + fileName480: s.fileNameMap["480"], + fileName720: s.fileNameMap["720"], + meanVolume: s.meanVolume, songArtistId: s.songArtistId, songGroupId: s.songGroupId, composerArtistId: s.composerArtistId, diff --git a/src/lib/db/schema/index.ts b/src/lib/db/schema/index.ts index 2b90535..fbc38ba 100644 --- a/src/lib/db/schema/index.ts +++ b/src/lib/db/schema/index.ts @@ -3,6 +3,7 @@ import { index, integer, primaryKey, + real, sqliteTable, text, uniqueIndex, @@ -87,6 +88,9 @@ export const songsTable = sqliteTable( * https://nawdist.animemusicquiz.com/{fileName} */ fileName: text("file_name"), + fileName480: text("file_name_480"), + fileName720: text("file_name_720"), + meanVolume: real("mean_volume"), /** * Primary artist/group ids for this song (nullable in source). @@ -123,7 +127,6 @@ export const songsTable = sqliteTable( }, (t) => ({ songIdIndex: index("songs_song_id_idx").on(t.songId), - fileNameIndex: index("songs_file_name_idx").on(t.fileName), songArtistIdIndex: index("songs_song_artist_id_idx").on(t.songArtistId), songGroupIdIndex: index("songs_song_group_id_idx").on(t.songGroupId), }), @@ -161,7 +164,9 @@ export const artistGroupsTable = sqliteTable( { songArtistId: integer("song_artist_id") .notNull() - .references(() => artistsTable.songArtistId, { onDelete: "cascade" }), + .references(() => artistsTable.songArtistId, { + onDelete: "cascade", + }), songGroupId: integer("song_group_id") .notNull() .references(() => groupsTable.songGroupId, { onDelete: "cascade" }), @@ -187,7 +192,9 @@ export const groupArtistMembersTable = sqliteTable( .references(() => groupsTable.songGroupId, { onDelete: "cascade" }), songArtistId: integer("song_artist_id") .notNull() - .references(() => artistsTable.songArtistId, { onDelete: "cascade" }), + .references(() => artistsTable.songArtistId, { + onDelete: "cascade", + }), }, (t) => ({ pk: primaryKey({ @@ -239,7 +246,9 @@ export const artistAltNamesTable = sqliteTable( */ songArtistId: integer("song_artist_id") .notNull() - .references(() => artistsTable.songArtistId, { onDelete: "cascade" }), + .references(() => artistsTable.songArtistId, { + onDelete: "cascade", + }), /** * The alternate-name entry is keyed by an artist id in the source: @@ -249,7 +258,9 @@ export const artistAltNamesTable = sqliteTable( */ altSongArtistId: integer("alt_song_artist_id") .notNull() - .references(() => artistsTable.songArtistId, { onDelete: "cascade" }), + .references(() => artistsTable.songArtistId, { + onDelete: "cascade", + }), name: text("name").notNull(), }, @@ -410,7 +421,10 @@ export const animeSongLinksTable = sqliteTable( dub: integer("dub").notNull(), }, (t) => ({ - pk: primaryKey({ name: "anime_songs_pk", columns: [t.annId, t.annSongId] }), + pk: primaryKey({ + name: "anime_songs_pk", + columns: [t.annId, t.annSongId], + }), annIdIndex: index("anime_songs_ann_id_idx").on(t.annId), songIdIndex: index("anime_songs_song_id_idx").on(t.annSongId), }), diff --git a/src/lib/types/amq/song.ts b/src/lib/types/amq/song.ts index 8dbe25b..2799055 100644 --- a/src/lib/types/amq/song.ts +++ b/src/lib/types/amq/song.ts @@ -22,8 +22,9 @@ export const AmqSongSchema = z.object({ globalPercent: z.number().int().min(0).max(100), fileName: z.string().nullable(), fileNameMap: z.object({ - 0: z.string().optional(), - 480: z.string().optional(), - 720: z.string().optional(), + "0": z.string().optional(), + "480": z.string().optional(), + "720": z.string().optional(), }), + meanVolume: z.number().negative().nullable(), });