u
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user