36 lines
1016 B
TypeScript
36 lines
1016 B
TypeScript
import {
|
|
integer,
|
|
pgTable,
|
|
serial,
|
|
text,
|
|
timestamp,
|
|
varchar,
|
|
} from "drizzle-orm/pg-core";
|
|
import { device } from "./device.schema";
|
|
import { relations } from "drizzle-orm";
|
|
|
|
export const link = pgTable("link", {
|
|
id: serial("id").primaryKey(),
|
|
|
|
token: text("token").notNull().unique(),
|
|
status: varchar("status", { length: 16 }).notNull().default("active"), // "active" | "inactive" | "expired" | "revoked"
|
|
appName: text("app_name").notNull(),
|
|
appPackage: text("app_package").notNull(),
|
|
|
|
linkedDeviceId: integer("linked_device_id").references(() => device.id, {
|
|
onDelete: "set null",
|
|
}),
|
|
|
|
expiresAt: timestamp("expires_at"),
|
|
lastAccessedAt: timestamp("last_accessed_at"),
|
|
createdAt: timestamp("created_at").notNull(),
|
|
updatedAt: timestamp("updated_at").notNull(),
|
|
});
|
|
|
|
export const linkRelations = relations(link, ({ one }) => ({
|
|
device: one(device, {
|
|
fields: [link.linkedDeviceId],
|
|
references: [device.id],
|
|
}),
|
|
}));
|