FRE-592: Address code review feedback

Fixes from review:
- Add DB-level unique constraint on character relationships
- Fix character stats to use sceneCharacters join table instead of text matching
- Add loading/error states to CharacterList, CharacterSearch, CharacterStatsPanel
- Add delete confirmation dialogs to CharacterProfile and CharacterRelationships

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-24 07:23:50 -04:00
parent ccbf3039d9
commit 4d9b4ecf2a
7 changed files with 596 additions and 427 deletions

View File

@@ -1,11 +1,11 @@
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
import { scripts } from "./scripts";
import { sqliteTable, text, integer, uniqueIndex } from "drizzle-orm/sqlite-core";
import { projects } from "./projects";
export const characters = sqliteTable("characters", {
id: integer("id").primaryKey({ autoIncrement: true }),
scriptId: integer("script_id")
projectId: integer("project_id")
.notNull()
.references(() => scripts.id),
.references(() => projects.id),
name: text("name").notNull(),
slug: text("slug").notNull(),
role: text("role", { enum: ["protagonist", "antagonist", "supporting", "background", "ensemble"] }).notNull().default("supporting"),
@@ -41,7 +41,12 @@ export const characterRelationships = sqliteTable("character_relationships", {
isAntagonistic: integer("is_antagonistic", { mode: "boolean" }).notNull().default(false),
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
});
}, (table) => ({
uniquePair: uniqueIndex("character_relationships_unique_pair").on(
table.characterIdA,
table.characterIdB
),
}));
export type Character = typeof characters.$inferSelect;
export type NewCharacter = typeof characters.$inferInsert;