Existing date fields in the tasks table have been changed from TEXT to INTEGER with mode set to timestamp. This will simplify date storage. There were a number of issues encountered with storing dates as typed strings.
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
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: int("open_date", { mode: "timestamp" }),
|
|
closeDate: int("close_date", { mode: "timestamp" }),
|
|
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],
|
|
}),
|
|
}));
|