This commit is contained in:
sebseb7
2025-12-25 03:28:12 +01:00
parent acbf168218
commit ce87faa551
6 changed files with 1183 additions and 13 deletions

View File

@@ -77,6 +77,35 @@ export function initDatabase(dbPath) {
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(created_by) REFERENCES users(id)
);
-- Rules for automation
CREATE TABLE IF NOT EXISTS rules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
type TEXT DEFAULT 'static',
enabled INTEGER DEFAULT 1,
position INTEGER DEFAULT 0,
conditions TEXT NOT NULL, -- JSON (nested AND/OR structure)
action TEXT NOT NULL, -- JSON object
created_by INTEGER,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(created_by) REFERENCES users(id)
);
-- Output events with RLE (same structure as sensor_events)
CREATE TABLE IF NOT EXISTS output_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp DATETIME NOT NULL,
until DATETIME,
channel TEXT NOT NULL,
value REAL,
data TEXT,
data_type TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_output_events_search
ON output_events(channel, timestamp);
`);
console.log('[DB] Database initialized successfully');