mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Create migration for watchlist/history/profiles
This commit is contained in:
parent
54131b6762
commit
22754442ad
40
api/drizzle/0017_watchlist.sql
Normal file
40
api/drizzle/0017_watchlist.sql
Normal file
@ -0,0 +1,40 @@
|
||||
CREATE TYPE "kyoo"."watchlist_status" AS ENUM('completed', 'watching', 'rewatching', 'dropped', 'planned');--> statement-breakpoint
|
||||
CREATE TABLE "kyoo"."history" (
|
||||
"pk" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "kyoo"."history_pk_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"profile_pk" integer NOT NULL,
|
||||
"entry_pk" integer NOT NULL,
|
||||
"video_pk" integer NOT NULL,
|
||||
"percent" integer DEFAULT 0 NOT NULL,
|
||||
"time" integer,
|
||||
"played_date" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT "percent_valid" CHECK ("kyoo"."history"."percent" between 0 and 100)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "kyoo"."profiles" (
|
||||
"pk" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "kyoo"."profiles_pk_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"id" uuid NOT NULL,
|
||||
CONSTRAINT "profiles_id_unique" UNIQUE("id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "kyoo"."watchlist" (
|
||||
"profile_pk" integer NOT NULL,
|
||||
"show_pk" integer NOT NULL,
|
||||
"status" "kyoo"."watchlist_status" NOT NULL,
|
||||
"seen_count" integer DEFAULT 0 NOT NULL,
|
||||
"next_entry" integer,
|
||||
"score" integer,
|
||||
"started_at" timestamp with time zone,
|
||||
"completed_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone NOT NULL,
|
||||
CONSTRAINT "watchlist_profile_pk_show_pk_pk" PRIMARY KEY("profile_pk","show_pk"),
|
||||
CONSTRAINT "score_percent" CHECK ("kyoo"."watchlist"."score" between 0 and 100)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."history" ADD CONSTRAINT "history_profile_pk_profiles_pk_fk" FOREIGN KEY ("profile_pk") REFERENCES "kyoo"."profiles"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."history" ADD CONSTRAINT "history_entry_pk_entries_pk_fk" FOREIGN KEY ("entry_pk") REFERENCES "kyoo"."entries"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."history" ADD CONSTRAINT "history_video_pk_videos_pk_fk" FOREIGN KEY ("video_pk") REFERENCES "kyoo"."videos"("pk") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."watchlist" ADD CONSTRAINT "watchlist_profile_pk_profiles_pk_fk" FOREIGN KEY ("profile_pk") REFERENCES "kyoo"."profiles"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."watchlist" ADD CONSTRAINT "watchlist_show_pk_shows_pk_fk" FOREIGN KEY ("show_pk") REFERENCES "kyoo"."shows"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "kyoo"."watchlist" ADD CONSTRAINT "watchlist_next_entry_entries_pk_fk" FOREIGN KEY ("next_entry") REFERENCES "kyoo"."entries"("pk") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "history_play_date" ON "kyoo"."history" USING btree ("played_date" DESC NULLS LAST);
|
1839
api/drizzle/meta/0017_snapshot.json
Normal file
1839
api/drizzle/meta/0017_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -120,6 +120,13 @@
|
||||
"when": 1742205790510,
|
||||
"tag": "0016_mqueue",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 17,
|
||||
"version": "7",
|
||||
"when": 1743944773824,
|
||||
"tag": "0017_watchlist",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
import { integer } from "drizzle-orm/pg-core";
|
||||
import { integer, uuid } from "drizzle-orm/pg-core";
|
||||
import { schema } from "./utils";
|
||||
|
||||
// user info is stored in keibi (the auth service).
|
||||
// this table is only there for relations.
|
||||
export const profiles = schema.table("profiles", {
|
||||
pk: integer().primaryKey().generatedAlwaysAsIdentity(),
|
||||
id: uuid().notNull().unique(),
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user