1- import { mkdirSync } from "node:fs"
1+ import { existsSync } from "node:fs"
22
33import { createDatabase } from "db0"
44import sqlite from "db0/connectors/node-sqlite"
@@ -10,16 +10,30 @@ import { ActuallyWorkingMigrationProvider } from "./file-provider.ts"
1010export const Source = {
1111 AniDB : "anidb" ,
1212 AniList : "anilist" ,
13+ AnimeCountdown : "animecountdown" ,
14+ AnimeNewsNetwork : "animenewsnetwork" ,
1315 AnimePlanet : "anime-planet" ,
1416 AniSearch : "anisearch" ,
1517 IMDB : "imdb" ,
1618 Kitsu : "kitsu" ,
1719 LiveChart : "livechart" ,
20+ MAL : "myanimelist" ,
21+ MediaType : "media" ,
22+ Simkl : "simkl" ,
1823 TheMovieDB : "themoviedb" ,
24+ TheMovieDBSeason : "themoviedb-season" ,
1925 TheTVDB : "thetvdb" ,
20- MAL : "myanimelist " ,
26+ TheTVDBSeason : "thetvdb-season " ,
2127} as const
2228export type SourceValue = ( typeof Source ) [ keyof typeof Source ]
29+ export const NonUniqueFields = [
30+ Source . IMDB ,
31+ Source . MediaType ,
32+ Source . TheMovieDB ,
33+ Source . TheMovieDBSeason ,
34+ Source . TheTVDB ,
35+ Source . TheTVDBSeason ,
36+ ] as ( keyof Relation ) [ ]
2337
2438export type Relation = {
2539 [ Source . AniDB ] ?: number
@@ -29,9 +43,15 @@ export type Relation = {
2943 [ Source . IMDB ] ?: `tt${string } `
3044 [ Source . Kitsu ] ?: number
3145 [ Source . LiveChart ] ?: number
46+ [ Source . AnimeNewsNetwork ] ?: number
3247 [ Source . TheMovieDB ] ?: number
3348 [ Source . TheTVDB ] ?: number
3449 [ Source . MAL ] ?: number
50+ [ Source . TheTVDBSeason ] ?: number
51+ [ Source . TheMovieDBSeason ] ?: number
52+ [ Source . Simkl ] ?: number
53+ [ Source . AnimeCountdown ] ?: number
54+ [ Source . MediaType ] ?: string
3555}
3656
3757export type OldRelation = Pick < Relation , "anidb" | "anilist" | "myanimelist" | "kitsu" >
@@ -41,9 +61,6 @@ export interface Database {
4161 relations : Relation
4262}
4363
44- // Ensure SQLite directory exists
45- mkdirSync ( "./dir" , { recursive : true } )
46-
4764const sqliteDb = sqlite (
4865 process . env . VITEST_POOL_ID == null
4966 ? { path : `./db/${ process . env . NODE_ENV ?? "development" } .sqlite3` }
@@ -58,6 +75,6 @@ export const db = new Kysely<Database>({
5875export const migrator = new Migrator ( {
5976 db,
6077 provider : new ActuallyWorkingMigrationProvider (
61- process . env . NODE_ENV !== "test" ? "dist /migrations" : "src /migrations" ,
78+ existsSync ( "src/migrations" ) ? "src /migrations" : "dist /migrations" ,
6279 ) ,
6380} )
0 commit comments