Update README with MQTT tables and parent_user_id documentation

Added documentation for:
- parent_user_id column in User table (hierarchical user management)
- mqtt_credentials table with device authentication
- mqtt_acl_rules table for topic permissions
- mqtt_sync_status table for broker synchronization
- All new database indexes
- Updated ER diagram with new relationships

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-29 13:53:27 +00:00
parent 632c92f3ee
commit e8a5f59e1d

View File

@@ -158,6 +158,7 @@ username TEXT UNIQUE NOT NULL
email TEXT
passwordHash TEXT NOT NULL
role TEXT NOT NULL DEFAULT 'VIEWER' -- ADMIN oder VIEWER
parent_user_id TEXT -- FK zu User.id (Hierarchie)
createdAt TEXT DEFAULT (datetime('now'))
updatedAt TEXT DEFAULT (datetime('now'))
lastLoginAt TEXT
@@ -176,10 +177,44 @@ createdAt TEXT DEFAULT (datetime('now'))
updatedAt TEXT DEFAULT (datetime('now'))
```
**MQTT Credentials Tabelle:**
```sql
id INTEGER PRIMARY KEY AUTOINCREMENT
device_id TEXT NOT NULL UNIQUE -- FK zu Device.id
mqtt_username TEXT NOT NULL UNIQUE
mqtt_password_hash TEXT NOT NULL
enabled INTEGER DEFAULT 1 -- 0 oder 1
created_at TEXT DEFAULT (datetime('now'))
updated_at TEXT DEFAULT (datetime('now'))
```
**MQTT ACL Rules Tabelle:**
```sql
id INTEGER PRIMARY KEY AUTOINCREMENT
device_id TEXT NOT NULL -- FK zu Device.id
topic_pattern TEXT NOT NULL
permission TEXT NOT NULL -- 'read', 'write', 'readwrite'
created_at TEXT DEFAULT (datetime('now'))
```
**MQTT Sync Status Tabelle:**
```sql
id INTEGER PRIMARY KEY CHECK (id = 1) -- Singleton
pending_changes INTEGER DEFAULT 0
last_sync_at TEXT
last_sync_status TEXT
created_at TEXT DEFAULT (datetime('now'))
updated_at TEXT DEFAULT (datetime('now'))
```
**Indexes:**
- `idx_user_username` ON User(username)
- `idx_user_parent` ON User(parent_user_id)
- `idx_device_owner` ON Device(ownerId)
- `idx_device_active` ON Device(isActive)
- `idx_mqtt_credentials_device` ON mqtt_credentials(device_id)
- `idx_mqtt_credentials_username` ON mqtt_credentials(mqtt_username)
- `idx_mqtt_acl_device` ON mqtt_acl_rules(device_id)
---
@@ -360,8 +395,11 @@ graph LR
```mermaid
erDiagram
USER ||--o{ USER : "parent_user_id"
USER ||--o{ DEVICE : owns
DEVICE ||--o{ LOCATION : tracks
DEVICE ||--o| MQTT_CREDENTIALS : has
DEVICE ||--o{ MQTT_ACL_RULES : has
USER {
string id PK
@@ -369,6 +407,7 @@ erDiagram
string email
string passwordHash
string role
string parent_user_id FK
datetime createdAt
datetime lastLoginAt
}
@@ -383,6 +422,33 @@ erDiagram
datetime createdAt
}
MQTT_CREDENTIALS {
int id PK
string device_id FK_UK
string mqtt_username UK
string mqtt_password_hash
boolean enabled
datetime created_at
datetime updated_at
}
MQTT_ACL_RULES {
int id PK
string device_id FK
string topic_pattern
string permission
datetime created_at
}
MQTT_SYNC_STATUS {
int id PK
int pending_changes
datetime last_sync_at
string last_sync_status
datetime created_at
datetime updated_at
}
LOCATION {
int id PK
float latitude