feat(db): add stream_sessions model for phase4 on-demand live flow

This commit is contained in:
2026-01-14 15:10:00 +00:00
parent dc65756db8
commit dc9c7df567
3 changed files with 41 additions and 0 deletions

View File

@@ -58,6 +58,21 @@ export const deviceCommands = pgTable('device_commands', {
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
});
export const streamSessions = pgTable('stream_sessions', {
id: uuid('id').defaultRandom().primaryKey(),
ownerUserId: uuid('owner_user_id').notNull().references(() => users.id),
cameraDeviceId: uuid('camera_device_id').notNull().references(() => devices.id),
requesterDeviceId: uuid('requester_device_id').notNull().references(() => devices.id),
status: varchar('status', { length: 32 }).default('requested').notNull(),
reason: varchar('reason', { length: 32 }).default('on_demand').notNull(),
streamKey: varchar('stream_key', { length: 255 }),
startedAt: timestamp('started_at', { withTimezone: true }),
endedAt: timestamp('ended_at', { withTimezone: true }),
metadata: jsonb('metadata').$type<Record<string, unknown> | null>().default(null),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
});
export const events = pgTable('events', {
id: uuid('id').defaultRandom().primaryKey(),
userId: uuid('user_id').notNull().references(() => users.id),
@@ -139,6 +154,7 @@ export const schema = {
devices,
deviceLinks,
deviceCommands,
streamSessions,
events,
videos,
notifications,

View File

@@ -0,0 +1,18 @@
CREATE TABLE "stream_sessions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"owner_user_id" uuid NOT NULL,
"camera_device_id" uuid NOT NULL,
"requester_device_id" uuid NOT NULL,
"status" varchar(32) DEFAULT 'requested' NOT NULL,
"reason" varchar(32) DEFAULT 'on_demand' NOT NULL,
"stream_key" varchar(255),
"started_at" timestamp with time zone,
"ended_at" timestamp with time zone,
"metadata" jsonb DEFAULT 'null'::jsonb,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "stream_sessions" ADD CONSTRAINT "stream_sessions_owner_user_id_users_id_fk" FOREIGN KEY ("owner_user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "stream_sessions" ADD CONSTRAINT "stream_sessions_camera_device_id_devices_id_fk" FOREIGN KEY ("camera_device_id") REFERENCES "public"."devices"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "stream_sessions" ADD CONSTRAINT "stream_sessions_requester_device_id_devices_id_fk" FOREIGN KEY ("requester_device_id") REFERENCES "public"."devices"("id") ON DELETE no action ON UPDATE no action;

View File

@@ -50,6 +50,13 @@
"when": 1770413956419,
"tag": "0006_steady_control_plane",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1770414956419,
"tag": "0007_live_stream_sessions",
"breakpoints": true
}
]
}