summaryrefslogtreecommitdiff
path: root/db/schema/tasks.ts
blob: fc4000bbedc3ee2dd4c594b9871c04793d510b3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { integer, pgTable, boolean, timestamp, varchar, primaryKey } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm"

import { generateId } from "@/lib/id"

export const tasks = pgTable("tasks", {
  id: varchar("id", { length: 30 })
    .$defaultFn(() => generateId())
    .primaryKey(),
  code: varchar("code", { length: 128 })
    .notNull()
    .unique()
    .default(
      sql`concat('TASK-', to_char(nextval('tasks_code_seq'), 'FM0000'))`
    )
  ,
  title: varchar("title", { length: 128 }),
  status: varchar("status", {
    length: 30,
    enum: ["todo", "in-progress", "done", "canceled"],
  })
    .notNull()
    .default("todo"),
  label: varchar("label", {
    length: 30,
    enum: ["bug", "feature", "enhancement", "documentation"],
  })
    .notNull()
    .default("bug"),
  priority: varchar("priority", {
    length: 30,
    enum: ["low", "medium", "high"],
  })
    .notNull()
    .default("low"),
  archived: boolean("archived").notNull().default(false),
  createdAt: timestamp("created_at").defaultNow().notNull(),
  updatedAt: timestamp("updated_at")
    .default(sql`current_timestamp`)
    .$onUpdate(() => new Date()),
})

export type Task = typeof tasks.$inferSelect
export type NewTask = Omit<Task, "code"> & {
  code?: string
}