-
Notifications
You must be signed in to change notification settings - Fork 252
/
schema.ts
44 lines (39 loc) · 1.13 KB
/
schema.ts
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
import { sql } from 'drizzle-orm'
import { drizzle } from 'drizzle-orm/d1'
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
import type { Env } from '~/types/Env'
const metadataColumns = {
id: integer('id').primaryKey({ autoIncrement: true }),
created: text('created')
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
modified: text('modified')
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
deleted: text('deleted'),
}
export const AnalyticsRefreshes = sqliteTable('AnalyticsRefreshes', {
...metadataColumns,
version: text('version').notNull(),
})
export const AnalyticsSimpleCallFeedback = sqliteTable(
'AnalyticsSimpleCallFeedback',
{
...metadataColumns,
version: text('version').notNull(),
experiencedIssues: integer('experiencedIssues').notNull(),
meetingId: text('meetingId').references(() => Meetings.id),
}
)
export const Meetings = sqliteTable('Meetings', {
...metadataColumns,
id: text('id').primaryKey(),
peakUserCount: integer('userCount').notNull(),
ended: text('ended'),
})
export function getDb(context: { env: Env }) {
if (!context.env.DB) {
return null
}
return drizzle(context.env.DB)
}