import { pgTable, uuid, varchar, text, jsonb, timestamp, index, uniqueIndex, foreignKey, } from "drizzle-orm/pg-core"; import { workspaces } from "./workspaces"; /** * Imported plan / epic / task rows sourced from repo markdown under `plans/`. * Scoped by workspace (tenant boundary in this app). */ export const markdownBacklogItems = pgTable( "markdown_backlog_items", { id: uuid("id").primaryKey().defaultRandom(), workspaceId: uuid("workspace_id") .notNull() .references(() => workspaces.id, { onDelete: "cascade" }), kind: varchar("kind", { length: 20 }).notNull(), slug: varchar("slug", { length: 200 }).notNull(), planSlug: varchar("plan_slug", { length: 200 }).notNull(), epicSlug: varchar("epic_slug", { length: 200 }), parentId: uuid("parent_id"), repoPath: text("repo_path").notNull(), title: varchar("title", { length: 500 }).notNull().default(""), status: varchar("status", { length: 50 }), priority: varchar("priority", { length: 20 }), owner: text("owner"), frontmatter: jsonb("frontmatter").$type | null>(), bodyMarkdown: text("body_markdown").notNull().default(""), contentHash: varchar("content_hash", { length: 64 }).notNull(), createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(), updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(), }, (table) => ({ parentFk: foreignKey({ columns: [table.parentId], foreignColumns: [table.id], }).onDelete("set null"), workspaceRepoUnique: uniqueIndex("markdown_backlog_workspace_repo_path_unique").on( table.workspaceId, table.repoPath, ), workspacePlanIdx: index("markdown_backlog_workspace_plan_idx").on( table.workspaceId, table.planSlug, ), parentIdIdx: index("markdown_backlog_parent_id_idx").on(table.parentId), workspaceKindIdx: index("markdown_backlog_workspace_kind_idx").on( table.workspaceId, table.kind, ), }), );