rewrite: TS monorepo — pi SDK stateless agents, Postgres+pg-boss, SvelteKit themed UI; legacy moved to legacy/

This commit is contained in:
ai-chess
2026-10-18 15:32:39 +03:00
parent e23a07f07b
commit 5be4bd1da4
321 changed files with 37840 additions and 158 deletions
+186
View File
@@ -0,0 +1,186 @@
CREATE TABLE "app_settings" (
"key" text PRIMARY KEY NOT NULL,
"value" jsonb NOT NULL
);
--> statement-breakpoint
CREATE TABLE "games" (
"id" text PRIMARY KEY NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"white_id" text NOT NULL,
"black_id" text NOT NULL,
"created_by" text,
"schedule_id" text,
"flags" jsonb NOT NULL,
"personas" jsonb NOT NULL,
"rated" boolean DEFAULT true NOT NULL,
"start_fen" text NOT NULL,
"fen" text NOT NULL,
"ply" integer DEFAULT 0 NOT NULL,
"pending_draw_by" text,
"result" text,
"termination" text,
"starts_at" timestamp with time zone,
"started_at" timestamp with time zone,
"finished_at" timestamp with time zone,
"rating_change" jsonb,
"accuracy" jsonb,
"interviews" jsonb DEFAULT '{}'::jsonb NOT NULL,
"last_words" jsonb DEFAULT '{}'::jsonb NOT NULL,
"review" jsonb,
"thumbnail" text,
"thumbnail_caption" text,
"thumbnail_meta" jsonb,
"cost_total" double precision DEFAULT 0 NOT NULL,
"error" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "moves" (
"id" text PRIMARY KEY NOT NULL,
"game_id" text NOT NULL,
"ply" integer NOT NULL,
"side" text NOT NULL,
"player_id" text NOT NULL,
"san" text,
"uci" text NOT NULL,
"fen_after" text NOT NULL,
"phrase" text,
"note" text,
"offered_draw" boolean DEFAULT false NOT NULL,
"illegal" boolean DEFAULT false NOT NULL,
"think_ms" integer DEFAULT 0 NOT NULL,
"usage" jsonb,
"eval" jsonb,
"classification" text,
"accuracy" double precision,
"turn_id" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "players" (
"id" text PRIMARY KEY NOT NULL,
"kind" text NOT NULL,
"slug" text NOT NULL,
"user_id" text,
"display_name" text NOT NULL,
"family" text,
"provider" text,
"model_id" text,
"thinking" text,
"variant" text,
"avatar" text,
"color" text,
"dumb" boolean DEFAULT false NOT NULL,
"skull" boolean DEFAULT false NOT NULL,
"options" jsonb DEFAULT '{}'::jsonb NOT NULL,
"active" boolean DEFAULT true NOT NULL,
"rating" double precision DEFAULT 1500 NOT NULL,
"rd" double precision DEFAULT 350 NOT NULL,
"vol" double precision DEFAULT 0.06 NOT NULL,
"games" integer DEFAULT 0 NOT NULL,
"wins" integer DEFAULT 0 NOT NULL,
"draws" integer DEFAULT 0 NOT NULL,
"losses" integer DEFAULT 0 NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "players_slug_unique" UNIQUE("slug"),
CONSTRAINT "players_user_id_unique" UNIQUE("user_id")
);
--> statement-breakpoint
CREATE TABLE "predictions" (
"id" text PRIMARY KEY NOT NULL,
"game_id" text NOT NULL,
"user_id" text NOT NULL,
"pick" text NOT NULL,
"points" integer,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "rating_history" (
"id" text PRIMARY KEY NOT NULL,
"player_id" text NOT NULL,
"game_id" text NOT NULL,
"before" double precision NOT NULL,
"after" double precision NOT NULL,
"rd" double precision NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "schedules" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"interval_minutes" integer DEFAULT 180 NOT NULL,
"announce_minutes" integer DEFAULT 30 NOT NULL,
"pool" jsonb DEFAULT '[]'::jsonb NOT NULL,
"flags" jsonb NOT NULL,
"random_personas" boolean DEFAULT true NOT NULL,
"next_run_at" timestamp with time zone,
"created_by" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "sessions" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"expires_at" timestamp with time zone NOT NULL
);
--> statement-breakpoint
CREATE TABLE "turns" (
"id" text PRIMARY KEY NOT NULL,
"game_id" text NOT NULL,
"ply" integer NOT NULL,
"side" text NOT NULL,
"player_id" text NOT NULL,
"attempt" integer DEFAULT 1 NOT NULL,
"status" text DEFAULT 'running' NOT NULL,
"transcript" jsonb DEFAULT '[]'::jsonb NOT NULL,
"usage" jsonb,
"outcome" text,
"error" text,
"started_at" timestamp with time zone DEFAULT now() NOT NULL,
"ended_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "usage_ledger" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text,
"game_id" text,
"player_id" text,
"kind" text NOT NULL,
"model" text NOT NULL,
"usage" jsonb NOT NULL,
"cost" double precision DEFAULT 0 NOT NULL,
"tokens" integer DEFAULT 0 NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" text PRIMARY KEY NOT NULL,
"username" text NOT NULL,
"password_hash" text NOT NULL,
"display_name" text NOT NULL,
"avatar" text,
"is_admin" boolean DEFAULT false NOT NULL,
"onboarded" boolean DEFAULT false NOT NULL,
"theme" text DEFAULT 'tabloid' NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "games" ADD CONSTRAINT "games_white_id_players_id_fk" FOREIGN KEY ("white_id") REFERENCES "public"."players"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "games" ADD CONSTRAINT "games_black_id_players_id_fk" FOREIGN KEY ("black_id") REFERENCES "public"."players"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "games" ADD CONSTRAINT "games_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "moves" ADD CONSTRAINT "moves_game_id_games_id_fk" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "players" ADD CONSTRAINT "players_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "predictions" ADD CONSTRAINT "predictions_game_id_games_id_fk" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "predictions" ADD CONSTRAINT "predictions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "turns" ADD CONSTRAINT "turns_game_id_games_id_fk" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "games_status" ON "games" USING btree ("status");--> statement-breakpoint
CREATE INDEX "games_created" ON "games" USING btree ("created_at");--> statement-breakpoint
CREATE UNIQUE INDEX "moves_game_ply" ON "moves" USING btree ("game_id","ply");--> statement-breakpoint
CREATE UNIQUE INDEX "predictions_game_user" ON "predictions" USING btree ("game_id","user_id");--> statement-breakpoint
CREATE INDEX "rating_history_player" ON "rating_history" USING btree ("player_id");--> statement-breakpoint
CREATE INDEX "turns_game_ply" ON "turns" USING btree ("game_id","ply");--> statement-breakpoint
CREATE INDEX "usage_user" ON "usage_ledger" USING btree ("user_id");--> statement-breakpoint
CREATE UNIQUE INDEX "users_username_lower" ON "users" USING btree (lower("username"));