From dc9c7df567823aad25315fc2e802e504832f217b Mon Sep 17 00:00:00 2001 From: Matiss Jurevics Date: Wed, 14 Jan 2026 15:10:00 +0000 Subject: [PATCH] feat(db): add stream_sessions model for phase4 on-demand live flow --- Backend/db/schema.ts | 16 ++++++++++++++++ Backend/drizzle/0007_live_stream_sessions.sql | 18 ++++++++++++++++++ Backend/drizzle/meta/_journal.json | 7 +++++++ 3 files changed, 41 insertions(+) create mode 100644 Backend/drizzle/0007_live_stream_sessions.sql diff --git a/Backend/db/schema.ts b/Backend/db/schema.ts index 3490fdf..cae365d 100644 --- a/Backend/db/schema.ts +++ b/Backend/db/schema.ts @@ -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 | 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, diff --git a/Backend/drizzle/0007_live_stream_sessions.sql b/Backend/drizzle/0007_live_stream_sessions.sql new file mode 100644 index 0000000..daa842e --- /dev/null +++ b/Backend/drizzle/0007_live_stream_sessions.sql @@ -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; diff --git a/Backend/drizzle/meta/_journal.json b/Backend/drizzle/meta/_journal.json index 483e3cb..118fe79 100644 --- a/Backend/drizzle/meta/_journal.json +++ b/Backend/drizzle/meta/_journal.json @@ -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 } ] }