Initial commit
This commit is contained in:
44
backend/prisma/migrations/20251208105610_init/migration.sql
Normal file
44
backend/prisma/migrations/20251208105610_init/migration.sql
Normal file
@@ -0,0 +1,44 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Device" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"name" TEXT NOT NULL,
|
||||
"ipAddress" TEXT NOT NULL,
|
||||
"port" INTEGER NOT NULL DEFAULT 80,
|
||||
"enabled" BOOLEAN NOT NULL DEFAULT true,
|
||||
"lastSeenAt" DATETIME,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Group" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"name" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "GroupDevice" (
|
||||
"groupId" TEXT NOT NULL,
|
||||
"deviceId" TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY ("groupId", "deviceId"),
|
||||
CONSTRAINT "GroupDevice_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "GroupDevice_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "Device" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Schedule" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"name" TEXT NOT NULL,
|
||||
"groupId" TEXT NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"cronExpression" TEXT NOT NULL,
|
||||
"timezone" TEXT NOT NULL DEFAULT 'Europe/London',
|
||||
"enabled" BOOLEAN NOT NULL DEFAULT true,
|
||||
"actionPayload" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "Schedule_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Schedule" ADD COLUMN "endCronExpression" TEXT;
|
||||
3
backend/prisma/migrations/migration_lock.toml
Normal file
3
backend/prisma/migrations/migration_lock.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "sqlite"
|
||||
57
backend/prisma/schema.prisma
Normal file
57
backend/prisma/schema.prisma
Normal file
@@ -0,0 +1,57 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Device {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
ipAddress String
|
||||
port Int @default(80)
|
||||
enabled Boolean @default(true)
|
||||
lastSeenAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
groups GroupDevice[]
|
||||
}
|
||||
|
||||
model Group {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
devices GroupDevice[]
|
||||
schedules Schedule[]
|
||||
}
|
||||
|
||||
model GroupDevice {
|
||||
groupId String
|
||||
deviceId String
|
||||
|
||||
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
|
||||
device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([groupId, deviceId])
|
||||
}
|
||||
|
||||
model Schedule {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
groupId String
|
||||
type String // 'PRESET' | 'PLAYLIST'
|
||||
cronExpression String
|
||||
endCronExpression String? // Optional: turn off lights at this time
|
||||
timezone String @default("Europe/London")
|
||||
enabled Boolean @default(true)
|
||||
actionPayload String // JSON string
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
group Group @relation(fields: [groupId], references: [id])
|
||||
}
|
||||
Reference in New Issue
Block a user