Add optional Home Assistant integration for battery percentage tracking
This commit is contained in:
@@ -1,3 +1,31 @@
|
||||
# Schema Migrations
|
||||
|
||||
## Adding Home Assistant fields (ha_entity_id, battery_percentage)
|
||||
|
||||
These columns were added in the Home Assistant integration feature. Existing databases
|
||||
need a manual migration — `create_all()` does not add columns to existing tables.
|
||||
|
||||
**Always snapshot first:**
|
||||
```bash
|
||||
cp batteries.db batteries.db.$(date +%Y-%m-%d).snapshot
|
||||
```
|
||||
|
||||
**SQLite:**
|
||||
```bash
|
||||
sqlite3 batteries.db "ALTER TABLE device ADD COLUMN ha_entity_id VARCHAR(100);"
|
||||
sqlite3 batteries.db "ALTER TABLE battery ADD COLUMN battery_percentage INTEGER;"
|
||||
```
|
||||
|
||||
**MariaDB / MySQL:**
|
||||
```sql
|
||||
ALTER TABLE device ADD COLUMN ha_entity_id VARCHAR(100) NULL;
|
||||
ALTER TABLE battery ADD COLUMN battery_percentage INT NULL;
|
||||
```
|
||||
|
||||
Both columns are nullable with no default, which is valid on all supported databases.
|
||||
|
||||
---
|
||||
|
||||
# Migrating from SQLite to MariaDB
|
||||
|
||||
This guide covers moving the Battery Tracker database from SQLite to MariaDB/MySQL
|
||||
|
||||
Reference in New Issue
Block a user