- Updated .gitignore to exclude generated files and database - Modified package.json to change dev script and add new dependencies - Removed src/index.ts and created app.ts for Elysia server initialization - Added environment variable configuration in config/env.ts - Implemented MQTT adapter in adapter/mqtt.ts for message handling - Created Prisma client in prisma/client.ts and defined schema in prisma/schema.prisma - Added seeding script in prisma/seed.ts for measurement points - Established logging utility in utils/logger.ts for structured logging - Created bed router in routes/bed.ts for handling bed-related routes
81 lines
No EOL
2.3 KiB
Text
81 lines
No EOL
2.3 KiB
Text
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
output = "../generated/prisma"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model MeasurementPoint {
|
|
id String @id @default(cuid())
|
|
sensorId String @unique // e.g., "head-1", "back-2"
|
|
label String // e.g., "Head Left", "Upper Back Center"
|
|
zone String // e.g., "head", "back", "shoulders"
|
|
x Int // X coordinate on bed layout
|
|
y Int // Y coordinate on bed layout
|
|
pin Int // Hardware pin number
|
|
|
|
// Threshold configuration
|
|
warningThreshold Int // Pressure value that triggers warning
|
|
alarmThreshold Int // Pressure value that triggers alarm
|
|
warningDelayMs Int // Delay before warning escalates to alarm
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
data MeasurementPointData[]
|
|
alerts Alert[]
|
|
}
|
|
|
|
model MeasurementPointData {
|
|
id String @id @default(cuid())
|
|
measurementPointId String
|
|
|
|
// Sensor reading data
|
|
value Int // Analog sensor value (0-4095)
|
|
|
|
// Timestamps
|
|
timestamp DateTime @default(now())
|
|
time String // Formatted time string
|
|
|
|
// Relations
|
|
measurementPoint MeasurementPoint @relation(fields: [measurementPointId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([measurementPointId, timestamp])
|
|
}
|
|
|
|
enum AlertType {
|
|
WARNING
|
|
ALARM
|
|
}
|
|
|
|
model Alert {
|
|
id String @id @default(cuid())
|
|
measurementPointId String
|
|
|
|
// Alert details
|
|
type AlertType
|
|
value Int // Sensor value that triggered alert
|
|
threshold Int // Threshold that was exceeded
|
|
|
|
// Alert state
|
|
acknowledged Boolean @default(false)
|
|
silenced Boolean @default(false)
|
|
|
|
// Timing
|
|
startTime DateTime @default(now())
|
|
endTime DateTime?
|
|
|
|
// Relations
|
|
measurementPoint MeasurementPoint @relation(fields: [measurementPointId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([measurementPointId, startTime])
|
|
@@index([type, acknowledged])
|
|
} |