db: split schema into separate files

This commit is contained in:
2026-02-05 19:19:25 -08:00
parent c8f577dab8
commit 88218b3567
17 changed files with 665 additions and 501 deletions

View File

@@ -0,0 +1,45 @@
import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
/**
* Core `anime` table.
*
* Normalized schema for AMQ source data (imported from JSON).
* Keeps original AMQ integer identifiers where present (annId, etc.).
*
* Source: AmqAnimeSchema
*/
export const animeTable = sqliteTable(
"anime",
{
/** AMQ anime ID */
annId: integer("ann_id").notNull().primaryKey(),
// External IDs from the source
aniListId: integer("anilist_id"),
malId: integer("mal_id").notNull(),
kitsuId: integer("kitsu_id"),
// Category object (name + number that can be number|string|null in source)
categoryName: text("category_name").notNull(),
categoryNumber: text("category_number"),
// Names
mainName: text("main_name").notNull(),
mainNameEn: text("main_name_en"),
mainNameJa: text("main_name_ja"),
// Season/year
year: integer("year").notNull(),
seasonId: integer("season_id").notNull(), // 0..3 from Season enum
// Counts
opCount: integer("op_count").notNull(),
edCount: integer("ed_count").notNull(),
insertCount: integer("insert_count").notNull(),
},
(t) => ({
aniListIndex: index("anime_anilist_id_uq").on(t.aniListId),
malIndex: index("anime_mal_id_uq").on(t.malId),
kitsuIndex: index("anime_kitsu_id_uq").on(t.kitsuId),
}),
);