refactor(backend): simplify media schema and recording metadata

This commit is contained in:
2026-03-11 17:15:00 +00:00
parent 662d8d7b90
commit c6919d8174
18 changed files with 223 additions and 113 deletions

View File

@@ -42,7 +42,7 @@ export const deviceLinks = pgTable(
}),
);
export const deviceCommands = pgTable('device_commands', {
export const commands = pgTable('commands', {
id: uuid('id').defaultRandom().primaryKey(),
ownerUserId: uuid('owner_user_id').notNull().references(() => users.id),
sourceDeviceId: uuid('source_device_id').notNull().references(() => devices.id),
@@ -65,8 +65,6 @@ export const streamSessions = pgTable('stream_sessions', {
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(),
// Legacy provider-backed fields are retained for compatibility with older sessions.
// SIMPLE_STREAMING relies on direct WebRTC signaling and does not populate them.
mediaProvider: varchar('media_provider', { length: 32 }).default('mock').notNull(),
mediaSessionId: varchar('media_session_id', { length: 255 }),
publishEndpoint: text('publish_endpoint'),
@@ -82,9 +80,9 @@ export const streamSessions = pgTable('stream_sessions', {
export const recordings = pgTable('recordings', {
id: uuid('id').defaultRandom().primaryKey(),
ownerUserId: uuid('owner_user_id').notNull().references(() => users.id),
streamSessionId: uuid('stream_session_id').notNull().references(() => streamSessions.id),
streamSessionId: uuid('stream_session_id').references(() => streamSessions.id),
cameraDeviceId: uuid('camera_device_id').notNull().references(() => devices.id),
requesterDeviceId: uuid('requester_device_id').notNull().references(() => devices.id),
requesterDeviceId: uuid('requester_device_id').references(() => devices.id),
eventId: uuid('event_id').references(() => events.id),
objectKey: varchar('object_key', { length: 1024 }),
bucket: varchar('bucket', { length: 255 }),
@@ -112,21 +110,6 @@ export const events = pgTable('events', {
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
});
export const videos = pgTable('videos', {
id: uuid('id').defaultRandom().primaryKey(),
eventId: uuid('event_id').references(() => events.id),
userId: uuid('user_id').notNull().references(() => users.id),
deviceId: uuid('device_id').notNull().references(() => devices.id),
objectKey: varchar('object_key', { length: 1024 }).notNull().unique(),
bucket: varchar('bucket', { length: 255 }).notNull(),
uploadUrl: text('upload_url').notNull(),
downloadUrl: text('download_url'),
status: varchar('status', { length: 32 }).notNull().default('pending'),
expiresAt: timestamp('expires_at', { withTimezone: true }),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
});
export const notifications = pgTable('notifications', {
id: uuid('id').defaultRandom().primaryKey(),
eventId: uuid('event_id').references(() => events.id).notNull(),
@@ -137,7 +120,7 @@ export const notifications = pgTable('notifications', {
isRead: boolean('is_read').default(false).notNull(),
});
export const pushNotifications = pgTable('push_notifications', {
export const notificationDeliveries = pgTable('notification_deliveries', {
id: uuid('id').defaultRandom().primaryKey(),
ownerUserId: uuid('owner_user_id').notNull().references(() => users.id),
recipientDeviceId: uuid('recipient_device_id').notNull().references(() => devices.id),
@@ -204,13 +187,12 @@ export const schema = {
users,
devices,
deviceLinks,
deviceCommands,
commands,
streamSessions,
recordings,
events,
videos,
notifications,
pushNotifications,
notificationDeliveries,
auditLogs,
accounts,
sessions,