-
-
Notifications
You must be signed in to change notification settings - Fork 13
New upstream fields #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
New upstream fields #906
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { mkdirSync } from "node:fs" | ||
| import { existsSync } from "node:fs" | ||
|
|
||
| import { createDatabase } from "db0" | ||
| import sqlite from "db0/connectors/node-sqlite" | ||
|
|
@@ -15,12 +15,27 @@ export const Source = { | |
| IMDB: "imdb", | ||
| Kitsu: "kitsu", | ||
| LiveChart: "livechart", | ||
| AnimeNewsNetwork: "animenewsnetwork", | ||
| NotifyMoe: "notify-moe", | ||
| TheMovieDB: "themoviedb", | ||
| TheMovieDBSeason: "themoviedb-season", | ||
| TheTVDB: "thetvdb", | ||
| TheTVDBSeason: "thetvdb-season", | ||
| MAL: "myanimelist", | ||
| Simkl: "simkl", | ||
| AnimeCountdown: "animecountdown", | ||
| MediaType: "media", | ||
| } as const | ||
| export type SourceValue = (typeof Source)[keyof typeof Source] | ||
| export const NonUniqueFields = [ | ||
| Source.IMDB, | ||
| Source.TheMovieDB, | ||
| Source.TheMovieDBSeason, | ||
| Source.TheTVDB, | ||
| Source.TheTVDBSeason, | ||
| Source.Simkl, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is simkl unique or not?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know for sure, no experience with the service but it does the whole "Global Movies and TV oh but also Anime" thing, so I preferred to err on the side of caution with non-unique |
||
| Source.MediaType, | ||
| ] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should either be a |
||
|
|
||
| export type Relation = { | ||
| [Source.AniDB]?: number | ||
|
|
@@ -30,10 +45,16 @@ export type Relation = { | |
| [Source.IMDB]?: `tt${string}` | ||
| [Source.Kitsu]?: number | ||
| [Source.LiveChart]?: number | ||
| [Source.AnimeNewsNetwork]?: number | ||
| [Source.NotifyMoe]?: string | ||
| [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"> | ||
|
|
@@ -43,9 +64,6 @@ export interface Database { | |
| relations: Relation | ||
| } | ||
|
|
||
| // Ensure SQLite directory exists | ||
| mkdirSync("./dir", { recursive: true }) | ||
|
|
||
| const sqliteDb = sqlite( | ||
| process.env.VITEST_POOL_ID == null | ||
| ? { path: `./db/${process.env.NODE_ENV ?? "development"}.sqlite3` } | ||
|
|
@@ -60,6 +78,6 @@ export const db = new Kysely<Database>({ | |
| export const migrator = new Migrator({ | ||
| db, | ||
| provider: new ActuallyWorkingMigrationProvider( | ||
| process.env.NODE_ENV !== "test" ? "dist/migrations" : "src/migrations", | ||
| existsSync("src/migrations") ? "src/migrations" : "dist/migrations", | ||
| ), | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { serve } from "h3" | ||
|
|
||
| import { createApp } from "./app.ts" | ||
| import { config } from "./config.ts" | ||
| import { config, Environment } from "./config.ts" | ||
| import { migrator } from "./db/db.ts" | ||
| import { updateRelations } from "./update.ts" | ||
|
|
||
|
|
@@ -11,7 +11,7 @@ const { NODE_ENV, PORT } = config | |
|
|
||
| const runUpdateScript = async () => updateRelations() | ||
|
|
||
| if (NODE_ENV === "production") { | ||
| if (NODE_ENV === Environment.Prod) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im not sure about this, it might be better to just remove the |
||
| void runUpdateScript() | ||
|
|
||
| // eslint-disable-next-line ts/no-misused-promises | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while i dont know exactly why you had issues with modifying the table, i do vaguely remember that sqlite's ill try to do this myself since im curious |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { Kysely } from "kysely" | ||
|
|
||
| export async function up(db: Kysely<unknown>): Promise<void> { | ||
| await db.schema.alterTable("relations").addColumn("themoviedb-season", "integer").execute() | ||
| await db.schema.alterTable("relations").addColumn("thetvdb-season", "integer").execute() | ||
| // unique, but sqlite can't add unique columns to tables | ||
| await db.schema.alterTable("relations").addColumn("animenewsnetwork", "integer").execute() | ||
| // unique, but sqlite can't add unique columns to tables | ||
| await db.schema.alterTable("relations").addColumn("animecountdown", "integer").execute() | ||
| await db.schema.alterTable("relations").addColumn("simkl", "integer").execute() | ||
| await db.schema.alterTable("relations").addColumn("media", "text").execute() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,16 @@ const createRelations = async <N extends number>( | |
| imdb: `tt${id++}`, | ||
| kitsu: id++, | ||
| livechart: id++, | ||
| animenewsnetwork: id++, | ||
| "notify-moe": `${id++}`, | ||
| themoviedb: id++, | ||
| "themoviedb-season": id++, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the seasons should probably be some number between 1-3 rather than an infinitely increasing number, you can hard code it for the tests |
||
| thetvdb: id++, | ||
| "thetvdb-season": id++, | ||
| myanimelist: id++, | ||
| simkl: id++, | ||
| animecountdown: id++, | ||
| media: `${id++}`, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. media cant be a string number
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it was weird, but I followed |
||
| })) | ||
|
|
||
| // Insert each relation | ||
|
|
@@ -80,10 +86,16 @@ describe("query params", () => { | |
| imdb: null!, | ||
| kitsu: null!, | ||
| livechart: null!, | ||
| animenewsnetwork: null!, | ||
| "notify-moe": null!, | ||
| themoviedb: null!, | ||
| "themoviedb-season": null!, | ||
| thetvdb: null!, | ||
| "thetvdb-season": null!, | ||
| myanimelist: null!, | ||
| simkl: null!, | ||
| animecountdown: null!, | ||
| media: null!, | ||
| } | ||
| await db.insertInto("relations").values(relation).execute() | ||
|
|
||
|
|
@@ -165,10 +177,16 @@ describe("json body", () => { | |
| imdb: null!, | ||
| kitsu: null!, | ||
| livechart: null!, | ||
| animenewsnetwork: null!, | ||
| "notify-moe": null!, | ||
| themoviedb: null!, | ||
| "themoviedb-season": null!, | ||
| thetvdb: null!, | ||
| "thetvdb-season": null!, | ||
| myanimelist: null!, | ||
| simkl: null!, | ||
| animecountdown: null!, | ||
| media: null!, | ||
| } | ||
| await db.insertInto("relations").values(relation).execute() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ export const includeSchema = v.object({ | |
| v.string(), | ||
| v.regex(/^[\-a-z,]+$/, "Invalid `include` query"), | ||
| v.minLength(1), | ||
| v.maxLength(100), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this change here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the added fields, the query length surpassed this limit. |
||
| v.maxLength(200), | ||
| ), | ||
| ), | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make sure that the order of fields in relations (both in docs and code) are always alphabetical
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe MAL was at the bottom in one place and it threw off my perception of anything else being alphabetized, I only noticed it yesterday with fresh eyes while splitting the PRs