feat: set up Drizzle
This commit is contained in:
30
src/models/schema.ts
Normal file
30
src/models/schema.ts
Normal 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];
|
||||
Reference in New Issue
Block a user