aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/lib/server/db/schema.ts
blob: c1bea43e3345d7f69e4ed77d3ad180869c07f0a5 (plain) (blame)
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
import { relations } from 'drizzle-orm';
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const syncSession = sqliteTable("session", {
	id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
	authzState: text("authzState"),
	accessTokenCreated: int("accessTokenCreated"),
	refreshTokenCreated: int("refreshTokenCreated"),
	tokens: text("tokens")
})

export const syncLog = sqliteTable("session_log", {
	id: text("id").primaryKey(),
	sessionId: text("session_id"),
	dateTime: text("date_time"),
	msg: text("msg")
})

export const syncLogRelation = relations(syncLog, ({ one }) => ({
	author: one(syncSession, {
		fields: [syncLog.sessionId],
		references: [syncSession.id],
	})
}))

export const syncSessionLogRelation = relations(syncSession, ({ many }) => ({
	logs: many(syncLog)
}))