wip: upsert things

This commit is contained in:
Zoe Roux 2024-11-30 04:56:53 +01:00
parent 3d20f063e9
commit 55b3f1cc8c
No known key found for this signature in database
7 changed files with 969 additions and 1 deletions

View File

@ -0,0 +1,56 @@
CREATE TABLE IF NOT EXISTS "kyoo"."entry_video_jointure" (
"entry" integer NOT NULL,
"video" integer NOT NULL,
"slug" varchar(255) NOT NULL,
CONSTRAINT "entry_video_jointure_entry_video_pk" PRIMARY KEY("entry","video"),
CONSTRAINT "entry_video_jointure_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
ALTER TABLE "kyoo"."entries_translation" RENAME TO "entry_translations";--> statement-breakpoint
ALTER TABLE "kyoo"."season_translation" RENAME TO "season_translations";--> statement-breakpoint
ALTER TABLE "kyoo"."videos" DROP CONSTRAINT "videos_slug_unique";--> statement-breakpoint
ALTER TABLE "kyoo"."entries" DROP CONSTRAINT "order_positive";--> statement-breakpoint
ALTER TABLE "kyoo"."shows" DROP CONSTRAINT "rating_valid";--> statement-breakpoint
ALTER TABLE "kyoo"."shows" DROP CONSTRAINT "runtime_valid";--> statement-breakpoint
ALTER TABLE "kyoo"."videos" DROP CONSTRAINT "part_pos";--> statement-breakpoint
ALTER TABLE "kyoo"."videos" DROP CONSTRAINT "version_pos";--> statement-breakpoint
ALTER TABLE "kyoo"."entry_translations" DROP CONSTRAINT "entries_translation_pk_entries_pk_fk";
--> statement-breakpoint
ALTER TABLE "kyoo"."season_translations" DROP CONSTRAINT "season_translation_pk_seasons_pk_fk";
--> statement-breakpoint
ALTER TABLE "kyoo"."entry_translations" DROP CONSTRAINT "entries_translation_pk_language_pk";--> statement-breakpoint
ALTER TABLE "kyoo"."season_translations" DROP CONSTRAINT "season_translation_pk_language_pk";--> statement-breakpoint
ALTER TABLE "kyoo"."entry_translations" ADD CONSTRAINT "entry_translations_pk_language_pk" PRIMARY KEY("pk","language");--> statement-breakpoint
ALTER TABLE "kyoo"."season_translations" ADD CONSTRAINT "season_translations_pk_language_pk" PRIMARY KEY("pk","language");--> statement-breakpoint
ALTER TABLE "kyoo"."entry_translations" ADD COLUMN "poster" jsonb;--> statement-breakpoint
ALTER TABLE "kyoo"."videos" ADD COLUMN "guess" jsonb DEFAULT '{}'::jsonb NOT NULL;--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "kyoo"."entry_video_jointure" ADD CONSTRAINT "entry_video_jointure_entry_entries_pk_fk" FOREIGN KEY ("entry") REFERENCES "kyoo"."entries"("pk") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "kyoo"."entry_video_jointure" ADD CONSTRAINT "entry_video_jointure_video_videos_pk_fk" FOREIGN KEY ("video") REFERENCES "kyoo"."videos"("pk") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "kyoo"."entry_translations" ADD CONSTRAINT "entry_translations_pk_entries_pk_fk" FOREIGN KEY ("pk") REFERENCES "kyoo"."entries"("pk") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "kyoo"."season_translations" ADD CONSTRAINT "season_translations_pk_seasons_pk_fk" FOREIGN KEY ("pk") REFERENCES "kyoo"."seasons"("pk") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "kyoo"."videos" DROP COLUMN IF EXISTS "slug";--> statement-breakpoint
ALTER TABLE "kyoo"."entries" ADD CONSTRAINT "order_positive" CHECK ("kyoo"."entries"."order" >= 0);--> statement-breakpoint
ALTER TABLE "kyoo"."shows" ADD CONSTRAINT "rating_valid" CHECK ("kyoo"."shows"."rating" between 0 and 100);--> statement-breakpoint
ALTER TABLE "kyoo"."shows" ADD CONSTRAINT "runtime_valid" CHECK ("kyoo"."shows"."runtime" >= 0);--> statement-breakpoint
ALTER TABLE "kyoo"."videos" ADD CONSTRAINT "part_pos" CHECK ("kyoo"."videos"."part" >= 0);--> statement-breakpoint
ALTER TABLE "kyoo"."videos" ADD CONSTRAINT "version_pos" CHECK ("kyoo"."videos"."version" >= 0);

View File

@ -0,0 +1,853 @@
{
"id": "0d5d6d22-dc13-4f3d-9975-cb7b38f628d4",
"prevId": "2210fd60-8e6a-4503-a2b3-56cc7f3cf15a",
"version": "7",
"dialect": "postgresql",
"tables": {
"kyoo.entries": {
"name": "entries",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "entries_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"show_pk": {
"name": "show_pk",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"order": {
"name": "order",
"type": "real",
"primaryKey": false,
"notNull": false
},
"season_number": {
"name": "season_number",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"episode_number": {
"name": "episode_number",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"type": {
"name": "type",
"type": "entry_type",
"typeSchema": "kyoo",
"primaryKey": false,
"notNull": true
},
"air_date": {
"name": "air_date",
"type": "date",
"primaryKey": false,
"notNull": false
},
"runtime": {
"name": "runtime",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"thumbnails": {
"name": "thumbnails",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"external_id": {
"name": "external_id",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"next_refresh": {
"name": "next_refresh",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"entries_show_pk_shows_pk_fk": {
"name": "entries_show_pk_shows_pk_fk",
"tableFrom": "entries",
"tableTo": "shows",
"schemaTo": "kyoo",
"columnsFrom": ["show_pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"entries_id_unique": {
"name": "entries_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"entries_slug_unique": {
"name": "entries_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
},
"entries_showPk_seasonNumber_episodeNumber_unique": {
"name": "entries_showPk_seasonNumber_episodeNumber_unique",
"nullsNotDistinct": false,
"columns": ["show_pk", "season_number", "episode_number"]
}
},
"policies": {},
"checkConstraints": {
"order_positive": {
"name": "order_positive",
"value": "\"kyoo\".\"entries\".\"order\" >= 0"
}
},
"isRLSEnabled": false
},
"kyoo.entry_translations": {
"name": "entry_translations",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"language": {
"name": "language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"tagline": {
"name": "tagline",
"type": "text",
"primaryKey": false,
"notNull": false
},
"poster": {
"name": "poster",
"type": "jsonb",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"entry_translations_pk_entries_pk_fk": {
"name": "entry_translations_pk_entries_pk_fk",
"tableFrom": "entry_translations",
"tableTo": "entries",
"schemaTo": "kyoo",
"columnsFrom": ["pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"entry_translations_pk_language_pk": {
"name": "entry_translations_pk_language_pk",
"columns": ["pk", "language"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.season_translations": {
"name": "season_translations",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"language": {
"name": "language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"poster": {
"name": "poster",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"thumbnail": {
"name": "thumbnail",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"banner": {
"name": "banner",
"type": "jsonb",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"season_translations_pk_seasons_pk_fk": {
"name": "season_translations_pk_seasons_pk_fk",
"tableFrom": "season_translations",
"tableTo": "seasons",
"schemaTo": "kyoo",
"columnsFrom": ["pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"season_translations_pk_language_pk": {
"name": "season_translations_pk_language_pk",
"columns": ["pk", "language"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.seasons": {
"name": "seasons",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "seasons_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"show_pk": {
"name": "show_pk",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"season_number": {
"name": "season_number",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"start_air": {
"name": "start_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"end_air": {
"name": "end_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"external_id": {
"name": "external_id",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"next_refresh": {
"name": "next_refresh",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"seasons_show_pk_shows_pk_fk": {
"name": "seasons_show_pk_shows_pk_fk",
"tableFrom": "seasons",
"tableTo": "shows",
"schemaTo": "kyoo",
"columnsFrom": ["show_pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"seasons_id_unique": {
"name": "seasons_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"seasons_slug_unique": {
"name": "seasons_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
},
"seasons_showPk_seasonNumber_unique": {
"name": "seasons_showPk_seasonNumber_unique",
"nullsNotDistinct": false,
"columns": ["show_pk", "season_number"]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.show_translations": {
"name": "show_translations",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"language": {
"name": "language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"tagline": {
"name": "tagline",
"type": "text",
"primaryKey": false,
"notNull": false
},
"aliases": {
"name": "aliases",
"type": "text[]",
"primaryKey": false,
"notNull": true
},
"tags": {
"name": "tags",
"type": "text[]",
"primaryKey": false,
"notNull": true
},
"poster": {
"name": "poster",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"thumbnail": {
"name": "thumbnail",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"banner": {
"name": "banner",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"logo": {
"name": "logo",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"trailer_url": {
"name": "trailer_url",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"show_translations_pk_shows_pk_fk": {
"name": "show_translations_pk_shows_pk_fk",
"tableFrom": "show_translations",
"tableTo": "shows",
"schemaTo": "kyoo",
"columnsFrom": ["pk"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"show_translations_pk_language_pk": {
"name": "show_translations_pk_language_pk",
"columns": ["pk", "language"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.shows": {
"name": "shows",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "shows_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"kind": {
"name": "kind",
"type": "show_kind",
"typeSchema": "kyoo",
"primaryKey": false,
"notNull": true
},
"genres": {
"name": "genres",
"type": "genres[]",
"primaryKey": false,
"notNull": true
},
"rating": {
"name": "rating",
"type": "smallint",
"primaryKey": false,
"notNull": false
},
"runtime": {
"name": "runtime",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "show_status",
"typeSchema": "kyoo",
"primaryKey": false,
"notNull": true
},
"start_air": {
"name": "start_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"end_air": {
"name": "end_air",
"type": "date",
"primaryKey": false,
"notNull": false
},
"original_language": {
"name": "original_language",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"external_id": {
"name": "external_id",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"next_refresh": {
"name": "next_refresh",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"shows_id_unique": {
"name": "shows_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"shows_slug_unique": {
"name": "shows_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
}
},
"policies": {},
"checkConstraints": {
"rating_valid": {
"name": "rating_valid",
"value": "\"kyoo\".\"shows\".\"rating\" between 0 and 100"
},
"runtime_valid": {
"name": "runtime_valid",
"value": "\"kyoo\".\"shows\".\"runtime\" >= 0"
}
},
"isRLSEnabled": false
},
"kyoo.entry_video_jointure": {
"name": "entry_video_jointure",
"schema": "kyoo",
"columns": {
"entry": {
"name": "entry",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"video": {
"name": "video",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"slug": {
"name": "slug",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"entry_video_jointure_entry_entries_pk_fk": {
"name": "entry_video_jointure_entry_entries_pk_fk",
"tableFrom": "entry_video_jointure",
"tableTo": "entries",
"schemaTo": "kyoo",
"columnsFrom": ["entry"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
},
"entry_video_jointure_video_videos_pk_fk": {
"name": "entry_video_jointure_video_videos_pk_fk",
"tableFrom": "entry_video_jointure",
"tableTo": "videos",
"schemaTo": "kyoo",
"columnsFrom": ["video"],
"columnsTo": ["pk"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"entry_video_jointure_entry_video_pk": {
"name": "entry_video_jointure_entry_video_pk",
"columns": ["entry", "video"]
}
},
"uniqueConstraints": {
"entry_video_jointure_slug_unique": {
"name": "entry_video_jointure_slug_unique",
"nullsNotDistinct": false,
"columns": ["slug"]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"kyoo.videos": {
"name": "videos",
"schema": "kyoo",
"columns": {
"pk": {
"name": "pk",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "videos_pk_seq",
"schema": "kyoo",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"id": {
"name": "id",
"type": "uuid",
"primaryKey": false,
"notNull": true,
"default": "gen_random_uuid()"
},
"path": {
"name": "path",
"type": "text",
"primaryKey": false,
"notNull": true
},
"rendering": {
"name": "rendering",
"type": "text",
"primaryKey": false,
"notNull": true
},
"part": {
"name": "part",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"version": {
"name": "version",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 1
},
"guess": {
"name": "guess",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"videos_id_unique": {
"name": "videos_id_unique",
"nullsNotDistinct": false,
"columns": ["id"]
},
"videos_path_unique": {
"name": "videos_path_unique",
"nullsNotDistinct": false,
"columns": ["path"]
}
},
"policies": {},
"checkConstraints": {
"part_pos": {
"name": "part_pos",
"value": "\"kyoo\".\"videos\".\"part\" >= 0"
},
"version_pos": {
"name": "version_pos",
"value": "\"kyoo\".\"videos\".\"version\" >= 0"
}
},
"isRLSEnabled": false
}
},
"enums": {
"kyoo.entry_type": {
"name": "entry_type",
"schema": "kyoo",
"values": ["unknown", "episode", "movie", "special", "extra"]
},
"kyoo.genres": {
"name": "genres",
"schema": "kyoo",
"values": [
"action",
"adventure",
"animation",
"comedy",
"crime",
"documentary",
"drama",
"family",
"fantasy",
"history",
"horror",
"music",
"mystery",
"romance",
"science-fiction",
"thriller",
"war",
"western",
"kids",
"reality",
"politics",
"soap",
"talk"
]
},
"kyoo.show_kind": {
"name": "show_kind",
"schema": "kyoo",
"values": ["serie", "movie"]
},
"kyoo.show_status": {
"name": "show_status",
"schema": "kyoo",
"values": ["unknown", "finished", "airing", "planned"]
}
},
"schemas": {
"kyoo": "kyoo"
},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@ -29,6 +29,13 @@
"when": 1731258712255,
"tag": "0003_order",
"breakpoints": true
},
{
"idx": 4,
"version": "7",
"when": 1732738409330,
"tag": "0004_jointures",
"breakpoints": true
}
]
}

View File

@ -0,0 +1,11 @@
import { db } from "~/db";
import { videos } from "~/db/schema";
import { bubble, bubbleVideo } from "~/models/examples";
import { seedMovie } from "./movies";
const videoExamples = [bubbleVideo];
export const seedTests = async () => {
await db.insert(videos).values(videoExamples).onConflictDoNothing();
await seedMovie(bubble)
};

View File

@ -39,7 +39,28 @@ export const seedMovie = async (
const [ret] = await tx
.insert(shows)
.values(movie)
.returning({ pk: shows.pk, id: shows.id, slug: shows.slug });
.onConflictDoUpdate({
target: shows.slug,
// we actually don't want to update anything, but we want to return the existing row.
// using a conflict update with a where false locks the database and ensure we don't have race conditions.
// it WONT work if we use triggers or need to handle conflicts on multiples collumns
// see https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql for more
set: { id: sql`excluded.id` },
setWhere: sql`false`,
})
.returning({
pk: shows.pk,
id: shows.id,
slug: shows.slug,
startAir: shows.startAir,
// https://stackoverflow.com/questions/39058213/differentiate-inserted-and-updated-rows-in-upsert-using-system-columns/39204667#39204667
conflict: sql`xmax = 0`.as("conflict"),
});
if (ret.conflict) {
if (getYear(ret.startAir) === getYear(movie.startAir)) {
return
}
}
// even if never shown to the user, a movie still has an entry.
const movieEntry: Entry = { type: "movie", ...bMovie };
@ -102,3 +123,8 @@ export const seedMovie = async (
videos: retVideos,
};
};
function getYear(date?: string | null) {
if (!date) return null;
return new Date(date).getUTCFullYear();
}

View File

@ -6,6 +6,7 @@ import { entries } from "./controllers/entries";
import { movies } from "./controllers/movies";
import { seasons } from "./controllers/seasons";
import { seed } from "./controllers/seed";
import { seedTests } from "./controllers/seed/examples";
import { series } from "./controllers/series";
import { videos } from "./controllers/videos";
import { db } from "./db";
@ -15,6 +16,7 @@ import { comment } from "./utils";
await migrate(db, { migrationsSchema: "kyoo", migrationsFolder: "./drizzle" });
if (process.env.SEED) {
await seedTests();
}
let secret = process.env.JWT_SECRET;

View File

@ -16,3 +16,16 @@ export const EntryTranslation = t.Object({
name: t.Nullable(t.String()),
description: t.Nullable(t.String()),
});
// export const SeedEntry = t.Intersect([
// Entry,
// t.Object({ videos: t.Optional(t.Array(Video)) }),
// ]);
// export type SeedEntry = typeof SeedEntry.static;
//
// export const SeedExtra = t.Intersect([
// Extra,
// t.Object({ video: t.Optional(Video) }),
// ]);
// export type SeedExtra = typeof SeedExtra.static;