u
This commit is contained in:
@@ -59,6 +59,24 @@ export function initDatabase(dbPath) {
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sensor_events_search
|
||||
ON sensor_events(device, channel, timestamp);
|
||||
|
||||
-- Phase 2: Authentication & Views
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL,
|
||||
password_hash TEXT NOT NULL,
|
||||
role TEXT NOT NULL CHECK(role IN ('admin', 'normal')),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS views (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT UNIQUE NOT NULL,
|
||||
config TEXT NOT NULL, -- JSON string of view configuration
|
||||
created_by INTEGER,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(created_by) REFERENCES users(id)
|
||||
);
|
||||
`);
|
||||
|
||||
console.log('[DB] Database initialized successfully');
|
||||
|
||||
Reference in New Issue
Block a user