-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdb.ts
More file actions
80 lines (72 loc) · 2.07 KB
/
db.ts
File metadata and controls
80 lines (72 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { existsSync } from "node:fs"
import { createDatabase } from "db0"
import sqlite from "db0/connectors/node-sqlite"
import { Kysely, Migrator } from "kysely"
import { Db0SqliteDialect } from "kysely-db0/sqlite"
import { ActuallyWorkingMigrationProvider } from "./file-provider.ts"
export const Source = {
AniDB: "anidb",
AniList: "anilist",
AnimeCountdown: "animecountdown",
AnimeNewsNetwork: "animenewsnetwork",
AnimePlanet: "anime-planet",
AniSearch: "anisearch",
IMDB: "imdb",
Kitsu: "kitsu",
LiveChart: "livechart",
MAL: "myanimelist",
MediaType: "media",
Simkl: "simkl",
TheMovieDB: "themoviedb",
TheMovieDBSeason: "themoviedb-season",
TheTVDB: "thetvdb",
TheTVDBSeason: "thetvdb-season",
} as const
export type SourceValue = (typeof Source)[keyof typeof Source]
export const NonUniqueFields = [
Source.IMDB,
Source.MediaType,
Source.TheMovieDB,
Source.TheMovieDBSeason,
Source.TheTVDB,
Source.TheTVDBSeason,
] as (keyof Relation)[]
export type Relation = {
[Source.AniDB]?: number
[Source.AniList]?: number
[Source.AnimePlanet]?: string
[Source.AniSearch]?: number
[Source.IMDB]?: `tt${string}`
[Source.Kitsu]?: number
[Source.LiveChart]?: number
[Source.AnimeNewsNetwork]?: number
[Source.TheMovieDB]?: number
[Source.TheTVDB]?: number
[Source.MAL]?: number
[Source.TheTVDBSeason]?: number
[Source.TheMovieDBSeason]?: number
[Source.Simkl]?: number
[Source.AnimeCountdown]?: number
[Source.MediaType]?: string
}
export type OldRelation = Pick<Relation, "anidb" | "anilist" | "myanimelist" | "kitsu">
// Define database schema for Kysely
export interface Database {
relations: Relation
}
const sqliteDb = sqlite(
process.env.VITEST_POOL_ID == null
? { path: `./db/${process.env.NODE_ENV ?? "development"}.sqlite3` }
: { name: ":memory:" },
)
const db0 = createDatabase(sqliteDb)
// Create Kysely instance
export const db = new Kysely<Database>({
dialect: new Db0SqliteDialect(db0),
})
export const migrator = new Migrator({
db,
provider: new ActuallyWorkingMigrationProvider(
existsSync("src/migrations") ? "src/migrations" : "dist/migrations",
),
})