import { relations, sql } from 'drizzle-orm'; import { numeric, text, pgTable, uuid, json } from "drizzle-orm/pg-core"; import type { Sb1Tokens } from '../sb1'; import type { SessionLogType } from '../session-log'; export const syncSession = pgTable("session", { id: uuid('id').primaryKey().default(sql`uuidv7()`), authzState: text("authzState"), accessTokenCreated: numeric("accessTokenCreated"), refreshTokenCreated: numeric("refreshTokenCreated"), tokens: json("tokens").$type() }) export const syncLog = pgTable("session_log", { id: uuid('id').primaryKey().default(sql`uuidv7()`), sessionId: text("session_id"), dateTime: text("date_time"), type: text("type").$type(), 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) }))