import { sql } from "drizzle-orm"; import { integer, primaryKey, sqliteTable, text, } from "drizzle-orm/sqlite-core"; export const deviceTokensTable = sqliteTable("device_tokens", { deviceId: text("device_id").primaryKey(), token: text("token").notNull().unique(), username: text("username"), /** Used to determine if a device hasn't been used in a while. Should start to ignore tokens where the device hasn't connected in about a month. */ lastConnectedAt: text("last_connected_at") .default(sql`(CURRENT_TIMESTAMP)`) .$onUpdate(() => sql`(CURRENT_TIMESTAMP)`), }); export const watchStatusTable = sqliteTable( "watch_status", { deviceId: text("device_id") .notNull() .references(() => deviceTokensTable.deviceId), titleId: integer("title_id").notNull(), }, (table) => ({ pk: primaryKey({ columns: [table.deviceId, table.titleId] }), }), ); export const tables = [watchStatusTable, deviceTokensTable];