mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fix entries fk and manually fix migrations
This commit is contained in:
parent
143ac6c721
commit
3f97ba729d
@ -1,5 +1,3 @@
|
||||
CREATE SCHEMA "kyoo";
|
||||
--> statement-breakpoint
|
||||
CREATE TYPE "kyoo"."entry_type" AS ENUM('unknown', 'episode', 'movie', 'special', 'extra');--> statement-breakpoint
|
||||
CREATE TYPE "kyoo"."genres" AS ENUM('action', 'adventure', 'animation', 'comedy', 'crime', 'documentary', 'drama', 'family', 'fantasy', 'history', 'horror', 'music', 'mystery', 'romance', 'science-fiction', 'thriller', 'war', 'western', 'kids', 'reality', 'politics', 'soap', 'talk');--> statement-breakpoint
|
||||
CREATE TYPE "kyoo"."show_kind" AS ENUM('serie', 'movie');--> statement-breakpoint
|
||||
@ -8,7 +6,7 @@ CREATE TABLE IF NOT EXISTS "kyoo"."entries" (
|
||||
"pk" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "kyoo"."entries_pk_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
"slug" varchar(255) NOT NULL,
|
||||
"show_id" integer,
|
||||
"show_pk" integer,
|
||||
"order" integer NOT NULL,
|
||||
"season_number" integer,
|
||||
"episode_number" integer,
|
||||
@ -21,7 +19,7 @@ CREATE TABLE IF NOT EXISTS "kyoo"."entries" (
|
||||
"next_refresh" timestamp with time zone,
|
||||
CONSTRAINT "entries_id_unique" UNIQUE("id"),
|
||||
CONSTRAINT "entries_slug_unique" UNIQUE("slug"),
|
||||
CONSTRAINT "entries_showId_seasonNumber_episodeNumber_unique" UNIQUE("show_id","season_number","episode_number"),
|
||||
CONSTRAINT "entries_showPk_seasonNumber_episodeNumber_unique" UNIQUE("show_pk","season_number","episode_number"),
|
||||
CONSTRAINT "order_positive" CHECK ("entries"."order" >= 0)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
@ -54,7 +52,7 @@ CREATE TABLE IF NOT EXISTS "kyoo"."shows" (
|
||||
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
"slug" varchar(255) NOT NULL,
|
||||
"kind" "kyoo"."show_kind" NOT NULL,
|
||||
"genres" "genres"[] NOT NULL,
|
||||
"genres" "kyoo"."genres"[] NOT NULL,
|
||||
"rating" smallint,
|
||||
"runtime" integer,
|
||||
"status" "kyoo"."show_status" NOT NULL,
|
||||
@ -86,7 +84,7 @@ CREATE TABLE IF NOT EXISTS "kyoo"."videos" (
|
||||
);
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "kyoo"."entries" ADD CONSTRAINT "entries_show_id_shows_id_fk" FOREIGN KEY ("show_id") REFERENCES "kyoo"."shows"("id") ON DELETE cascade ON UPDATE no action;
|
||||
ALTER TABLE "kyoo"."entries" ADD CONSTRAINT "entries_show_pk_shows_pk_fk" FOREIGN KEY ("show_pk") REFERENCES "kyoo"."shows"("pk") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "88c55813-3ceb-468d-b010-c2b8f7fa875e",
|
||||
"id": "82560792-5f4a-4723-9543-808719ade682",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
@ -38,8 +38,8 @@
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"show_id": {
|
||||
"name": "show_id",
|
||||
"show_pk": {
|
||||
"name": "show_pk",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
@ -110,13 +110,13 @@
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"entries_show_id_shows_id_fk": {
|
||||
"name": "entries_show_id_shows_id_fk",
|
||||
"entries_show_pk_shows_pk_fk": {
|
||||
"name": "entries_show_pk_shows_pk_fk",
|
||||
"tableFrom": "entries",
|
||||
"tableTo": "shows",
|
||||
"schemaTo": "kyoo",
|
||||
"columnsFrom": ["show_id"],
|
||||
"columnsTo": ["id"],
|
||||
"columnsFrom": ["show_pk"],
|
||||
"columnsTo": ["pk"],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
@ -133,10 +133,10 @@
|
||||
"nullsNotDistinct": false,
|
||||
"columns": ["slug"]
|
||||
},
|
||||
"entries_showId_seasonNumber_episodeNumber_unique": {
|
||||
"name": "entries_showId_seasonNumber_episodeNumber_unique",
|
||||
"entries_showPk_seasonNumber_episodeNumber_unique": {
|
||||
"name": "entries_showPk_seasonNumber_episodeNumber_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": ["show_id", "season_number", "episode_number"]
|
||||
"columns": ["show_pk", "season_number", "episode_number"]
|
||||
}
|
||||
},
|
||||
"policies": {},
|
||||
|
@ -5,7 +5,7 @@
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1731105447005,
|
||||
"when": 1731105746157,
|
||||
"tag": "0000_init",
|
||||
"breakpoints": true
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export const entries = schema.table(
|
||||
pk: integer().primaryKey().generatedAlwaysAsIdentity(),
|
||||
id: uuid().notNull().unique().defaultRandom(),
|
||||
slug: varchar({ length: 255 }).notNull().unique(),
|
||||
showId: integer().references(() => shows.id, { onDelete: "cascade" }),
|
||||
showPk: integer().references(() => shows.pk, { onDelete: "cascade" }),
|
||||
order: integer().notNull(),
|
||||
seasonNumber: integer(),
|
||||
episodeNumber: integer(),
|
||||
@ -43,7 +43,7 @@ export const entries = schema.table(
|
||||
nextRefresh: timestamp({ withTimezone: true, mode: "string" }),
|
||||
},
|
||||
(t) => [
|
||||
unique().on(t.showId, t.seasonNumber, t.episodeNumber),
|
||||
unique().on(t.showPk, t.seasonNumber, t.episodeNumber),
|
||||
check("order_positive", sql`${t.order} >= 0`),
|
||||
],
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user