feat: extend database schema with devices and notifications tables, update events and videos tables for improved relationships
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { pgTable, timestamp, uuid, varchar, text } from 'drizzle-orm/pg-core';
|
import { pgTable, timestamp, uuid, varchar, text, boolean } from 'drizzle-orm/pg-core';
|
||||||
|
|
||||||
export const users = pgTable('users', {
|
export const users = pgTable('users', {
|
||||||
id: uuid('id').defaultRandom().primaryKey(),
|
id: uuid('id').defaultRandom().primaryKey(),
|
||||||
@@ -8,17 +8,35 @@ export const users = pgTable('users', {
|
|||||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const devices = pgTable('devices', {
|
||||||
|
id: uuid('id').defaultRandom().primaryKey(),
|
||||||
|
userId: uuid('user_id').notNull().references(() => users.id),
|
||||||
|
name: varchar('name', { length: 255 }),
|
||||||
|
isCamera: boolean('is_camera').default(false).notNull(),
|
||||||
|
lastSeenAt: timestamp('last_seen_at', { withTimezone: true }),
|
||||||
|
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
export const events = pgTable('events', {
|
export const events = pgTable('events', {
|
||||||
id: uuid('id').defaultRandom().primaryKey(),
|
id: uuid('id').defaultRandom().primaryKey(),
|
||||||
creatorId: uuid('creator_id').references(() => users.id),
|
userId: uuid('user_id').notNull().references(() => users.id),
|
||||||
title: varchar('title', { length: 255 }).notNull(),
|
deviceId: uuid('device_id').references(() => devices.id),
|
||||||
|
title: varchar('title', { length: 255 }),
|
||||||
|
triggeredBy: varchar('triggered_by', { length: 64 }).default('motion'),
|
||||||
|
status: varchar('status', { length: 32 }).default('recording').notNull(),
|
||||||
|
startedAt: timestamp('started_at', { withTimezone: true }).notNull(),
|
||||||
|
endedAt: timestamp('ended_at', { withTimezone: true }),
|
||||||
|
notifiedAt: timestamp('notified_at', { withTimezone: true }),
|
||||||
|
videoUrl: varchar('video_url', { length: 1024 }).unique(),
|
||||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||||
videoUrl: varchar('video_url', { length: 255 }).notNull().unique(),
|
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const videos = pgTable('videos', {
|
export const videos = pgTable('videos', {
|
||||||
id: uuid('id').defaultRandom().primaryKey(),
|
id: uuid('id').defaultRandom().primaryKey(),
|
||||||
|
eventId: uuid('event_id').references(() => events.id),
|
||||||
userId: uuid('user_id').notNull().references(() => users.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(),
|
objectKey: varchar('object_key', { length: 1024 }).notNull().unique(),
|
||||||
bucket: varchar('bucket', { length: 255 }).notNull(),
|
bucket: varchar('bucket', { length: 255 }).notNull(),
|
||||||
uploadUrl: text('upload_url').notNull(),
|
uploadUrl: text('upload_url').notNull(),
|
||||||
@@ -28,3 +46,13 @@ export const videos = pgTable('videos', {
|
|||||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||||
updatedAt: timestamp('updated_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(),
|
||||||
|
userId: uuid('user_id').references(() => users.id).notNull(),
|
||||||
|
sentAt: timestamp('sent_at', { withTimezone: true }).defaultNow().notNull(),
|
||||||
|
channel: varchar('channel', { length: 32 }).notNull(),
|
||||||
|
status: varchar('status', { length: 32 }).default('queued').notNull(),
|
||||||
|
isRead: boolean('is_read').default(false).notNull(),
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user