From 450bcf173f8918a120ef8cee7966e6de080222da Mon Sep 17 00:00:00 2001 From: themodrnhakr Date: Fri, 26 Sep 2025 14:25:25 -0500 Subject: [PATCH] Add task related tables. Pivoting from "records" to a combination of "tasks", "micro-tasks", "assets", and a few others. --- src/lib/server/db/db.ts | 3 +- src/lib/server/db/schema/tasks.ts | 71 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/lib/server/db/schema/tasks.ts diff --git a/src/lib/server/db/db.ts b/src/lib/server/db/db.ts index 35eab52..eda006d 100644 --- a/src/lib/server/db/db.ts +++ b/src/lib/server/db/db.ts @@ -1,7 +1,8 @@ import * as schema2 from "$lib/server/db/schema/records"; import * as schema1 from "$lib/server/db/schema/recordTypes"; +import * as schema3 from "$lib/server/db/schema/tasks"; import { Database } from "bun:sqlite"; import { drizzle } from "drizzle-orm/bun-sqlite"; const sqlite = new Database("sqlite.db"); -export const db = drizzle({ client: sqlite, schema: { ...schema1, ...schema2 } }); +export const db = drizzle({ client: sqlite, schema: { ...schema1, ...schema2, ...schema3 } }); diff --git a/src/lib/server/db/schema/tasks.ts b/src/lib/server/db/schema/tasks.ts new file mode 100644 index 0000000..ea2e3f6 --- /dev/null +++ b/src/lib/server/db/schema/tasks.ts @@ -0,0 +1,71 @@ +import { relations, sql } from "drizzle-orm"; +import { type AnySQLiteColumn, check, int, sqliteTable, text } from "drizzle-orm/sqlite-core"; + +export type TaskIntegrationConfigs = { + source_control: Array<{ + repo_id: string; + commits: Array<{ + hash: string; + message: string; + description?: string; + }>; + }>; +}; + +export const taskTypes = sqliteTable("task_types", { + id: int("id").primaryKey({ autoIncrement: true }), + name: text("name").unique(), + prefix: text("prefix").unique(), +}, (table) => [ + check("prefix_limit", sql`LENGTH(${table.prefix}) <=2`), +]); + +export const taskTypesRelations = relations(taskTypes, ({ many }) => ({ + tasks: many(tasks), +})); + +export const tasks = sqliteTable("tasks", { + id: int("id").primaryKey({ autoIncrement: true }), + taskId: text("task_id").unique(), + description: text("description"), + type: int("type").references(() => taskTypes.id), + subtype: text("subtype"), + openDate: text("open_date").$type(), + closeDate: text("close_date").$type(), + status: text("status"), + priority: text("priority"), + parent: int("parent").references((): AnySQLiteColumn => tasks.id), + body: text("body"), + bodyHistory: text("body_history"), + checklist: text("checklist", { mode: "json" }).$type< + { + enabled: boolean; + entries: Array<{ + group?: string; + sort_order: number; + checked: boolean; + text: string; + }>; + } + >(), + updateChain: text("udpate_chain", { mode: "json" }).$type< + { + enabled: boolean; + entries: Array<{ + updated_on: Date["toISOString"]; + updated_by: string; + body: string; + }>; + } + >(), + integrations: text("integrations", { mode: "json" }).$type< + { type: keyof TaskIntegrationConfigs; config: TaskIntegrationConfigs["source_control"] } + >(), +}); + +export const tasksRelations = relations(tasks, ({ one }) => ({ + type: one(taskTypes, { + fields: [tasks.type], + references: [taskTypes.id], + }), +}));