Files
sexy/lib/db/schema.ts
T
valknarandClaude Sonnet 5 401b9b5033
CI / Build and push image (push) Successful in 1m41s
CI / Static checks (push) Successful in 2m12s
Remove recordings feature, replay sessions directly, bump to 0.6.0
Recordings were just a thin named pointer over an already-captured
session's events, so the whole separate feature (recordings table, API
routes, pages, UI) is gone: any completed session can now be named and
replayed directly. Replaying no longer creates a session or duplicates
events of its own - it just bumps the source session's playCount/lastPlayedAt.

Also renames play_sessions/playSession(s) to sessions/session(s) throughout
the schema, queries, API routes, and UI for consistency, and updates the
README to match the new flow.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-27 21:38:51 +02:00

86 lines
3.5 KiB
TypeScript

import { sqliteTable, text, integer, real, index, type AnySQLiteColumn } from "drizzle-orm/sqlite-core";
export interface DeviceCapabilities {
/** Buttplug OutputType strings (Vibrate/Rotate/Position/...) present on any feature. */
outputs: string[];
featureCount: number;
}
// No `users` table - the app is gated by a single ACCESS_PASSWORD env var
// (see lib/auth/session.ts), not a persisted account.
export const devices = sqliteTable("devices", {
id: integer("id").primaryKey({ autoIncrement: true }),
displayName: text("display_name"),
// Web Bluetooth exposes no stable hardware id, only the advertised name -
// this is the best identity key available across browser sessions.
bleName: text("ble_name").notNull(),
deviceClass: text("device_class"),
capabilities: text("capabilities", { mode: "json" }).$type<DeviceCapabilities>(),
createdAt: integer("created_at").notNull(),
lastConnectedAt: integer("last_connected_at"),
});
export const sessions = sqliteTable("sessions", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name"),
description: text("description"),
kind: text("kind", { enum: ["live", "replay"] }).notNull(),
// Self-referencing: which session's events this session replayed, if any.
replayedSessionId: integer("replayed_session_id").references((): AnySQLiteColumn => sessions.id, {
onDelete: "set null",
}),
status: text("status", { enum: ["active", "completed", "aborted"] }).notNull().default("active"),
startedAt: integer("started_at").notNull(),
endedAt: integer("ended_at"),
durationMs: integer("duration_ms"),
notes: text("notes"),
// How many times (and when) this session's events have been replayed -
// any completed session can be a replay source, there's no separate
// "saved recording" concept anymore.
playCount: integer("play_count").notNull().default(0),
lastPlayedAt: integer("last_played_at"),
});
export const sessionDevices = sqliteTable(
"session_devices",
{
id: integer("id").primaryKey({ autoIncrement: true }),
sessionId: integer("session_id")
.notNull()
.references(() => sessions.id, { onDelete: "cascade" }),
deviceId: integer("device_id")
.notNull()
.references(() => devices.id, { onDelete: "restrict" }),
slotLabel: text("slot_label").notNull(),
connectedAt: integer("connected_at").notNull(),
disconnectedAt: integer("disconnected_at"),
},
(table) => [index("session_devices_session_id_idx").on(table.sessionId)],
);
export const sessionEvents = sqliteTable(
"session_events",
{
id: integer("id").primaryKey({ autoIncrement: true }),
sessionId: integer("session_id")
.notNull()
.references(() => sessions.id, { onDelete: "cascade" }),
sessionDeviceId: integer("session_device_id")
.notNull()
.references(() => sessionDevices.id, { onDelete: "cascade" }),
// Relative to the session's startedAt, not wall-clock - keeps timeline
// math and replay scheduling drift-free and reproducible.
tsMs: integer("ts_ms").notNull(),
commandType: text("command_type", { enum: ["vibrate", "rotate", "linear", "stop"] }).notNull(),
featureIndex: integer("feature_index").notNull(),
value: real("value").notNull(),
durationMs: integer("duration_ms"),
rawPayload: text("raw_payload", { mode: "json" }),
},
(table) => [
index("session_events_session_ts_idx").on(table.sessionId, table.tsMs),
index("session_events_session_device_idx").on(table.sessionDeviceId),
],
);