import { relations, sql } from 'drizzle-orm'; import { numeric, text, pgTable, uuid, jsonb } from "drizzle-orm/pg-core"; import type { SessionLogType } from '../session-log'; import type { Sb1Tokens, Sb1Transaction, Sb1TransactionDetails } from '$lib/shared'; export const SyncSessionTable = pgTable("session", { id: uuid('id').primaryKey().default(sql`uuidv7()`), authzState: text("authzState"), accessTokenCreated: numeric("accessTokenCreated"), refreshTokenCreated: numeric("refreshTokenCreated"), tokens: jsonb("tokens").$type() }) export const SyncLogTable = 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 TransactionsTable = pgTable("transactions", { transaction: jsonb("transaction").$type(), details: jsonb("details").$type() }) export const SyncLogRelation = relations(SyncLogTable, ({ one }) => ({ author: one(SyncSessionTable, { fields: [SyncLogTable.sessionId], references: [SyncSessionTable.id], }) })) export const SyncSessionLogRelation = relations(SyncSessionTable, ({ many }) => ({ logs: many(SyncLogTable) }))