feat: set up Drizzle

This commit is contained in:
2024-06-12 09:29:58 -04:00
parent 5843dfdeb2
commit 06bb8f65fb
13 changed files with 403 additions and 5 deletions

30
src/models/schema.ts Normal file
View File

@@ -0,0 +1,30 @@
import { sql } from "drizzle-orm";
import {
integer,
primaryKey,
sqliteTable,
text,
} from "drizzle-orm/sqlite-core";
export const tokenTable = sqliteTable("token", {
deviceId: text("device_id").primaryKey(),
token: text("token").notNull(),
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)`),
});
export const watchStatusTable = sqliteTable(
"watch_status",
{
deviceId: text("device_id")
.notNull()
.references(() => tokenTable.deviceId),
titleId: integer("title_id").notNull(),
},
(table) => ({
pk: primaryKey({ columns: [table.deviceId, table.titleId] }),
}),
);
export const tables = [watchStatusTable, tokenTable];