-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathschema.ts
More file actions
73 lines (69 loc) · 2.69 KB
/
schema.ts
File metadata and controls
73 lines (69 loc) · 2.69 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { sql } from "drizzle-orm"
import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core"
export const keyValue = sqliteTable("keyValue", {
key: text().primaryKey(),
value: text().notNull(),
createdAt: integer({ mode: "timestamp_ms" })
.notNull()
.$defaultFn(() => new Date()),
updatedAt: integer({ mode: "timestamp_ms" })
.notNull()
.$defaultFn(() => new Date())
.$onUpdateFn(() => new Date())
})
export const helperEvents = sqliteTable(
"helper_events",
{
id: integer().primaryKey({ autoIncrement: true }),
eventType: text("event_type").notNull().default("helper_command"),
threadId: text("thread_id"),
messageCount: integer("message_count"),
eventTime: text("event_time").notNull(),
command: text().notNull(),
invokedById: text("invoked_by_id"),
invokedByUsername: text("invoked_by_username"),
invokedByGlobalName: text("invoked_by_global_name"),
receivedAt: text("received_at")
.notNull()
.default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`),
rawPayload: text("raw_payload").notNull()
},
(table) => [
index("idx_helper_events_event_time").on(table.eventTime),
index("idx_helper_events_command").on(table.command),
index("idx_helper_events_thread_id").on(table.threadId),
index("idx_helper_events_invoked_by_id").on(table.invokedById),
index("idx_helper_events_event_type").on(table.eventType),
index("idx_helper_events_thread_time").on(table.threadId, table.eventTime)
]
)
export const trackedThreads = sqliteTable(
"tracked_threads",
{
id: integer().primaryKey({ autoIncrement: true }),
threadId: text("thread_id").notNull().unique(),
createdAt: text("created_at").notNull(),
lastChecked: text("last_checked"),
solved: integer().notNull().default(0),
warningLevel: integer("warning_level").notNull().default(0),
closed: integer().notNull().default(0),
lastMessageCount: integer("last_message_count"),
receivedAt: text("received_at")
.notNull()
.default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`),
rawPayload: text("raw_payload").notNull()
},
(table) => [
index("idx_tracked_threads_solved").on(table.solved),
index("idx_tracked_threads_last_checked").on(table.lastChecked),
index("idx_tracked_threads_received_at").on(table.receivedAt),
index("idx_tracked_threads_closed").on(table.closed),
index("idx_tracked_threads_warning_level").on(table.warningLevel)
]
)
export type KeyValue = typeof keyValue.$inferSelect
export type NewKeyValue = typeof keyValue.$inferInsert
export type HelperEvent = typeof helperEvents.$inferSelect
export type NewHelperEvent = typeof helperEvents.$inferInsert
export type TrackedThread = typeof trackedThreads.$inferSelect
export type NewTrackedThread = typeof trackedThreads.$inferInsert