mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-19 15:26:59 +00:00
Update database schema for v8 schema (#13784)
This commit is contained in:
parent
1530e60036
commit
1a14367b24
@ -47,9 +47,10 @@ CREATE TABLE events (
|
|||||||
origin VARCHAR(32),
|
origin VARCHAR(32),
|
||||||
time_fired DATETIME,
|
time_fired DATETIME,
|
||||||
created DATETIME,
|
created DATETIME,
|
||||||
|
context_id VARCHAR(36),
|
||||||
|
context_user_id VARCHAR(36), context_parent_id CHARACTER(36),
|
||||||
PRIMARY KEY (event_id)
|
PRIMARY KEY (event_id)
|
||||||
)
|
)
|
||||||
CREATE INDEX ix_events_event_type ON events (event_type)
|
|
||||||
CREATE TABLE recorder_runs (
|
CREATE TABLE recorder_runs (
|
||||||
run_id INTEGER NOT NULL,
|
run_id INTEGER NOT NULL,
|
||||||
start DATETIME,
|
start DATETIME,
|
||||||
@ -59,22 +60,41 @@ CREATE TABLE recorder_runs (
|
|||||||
PRIMARY KEY (run_id),
|
PRIMARY KEY (run_id),
|
||||||
CHECK (closed_incorrect IN (0, 1))
|
CHECK (closed_incorrect IN (0, 1))
|
||||||
)
|
)
|
||||||
|
CREATE TABLE schema_changes (
|
||||||
|
change_id INTEGER NOT NULL,
|
||||||
|
schema_version INTEGER,
|
||||||
|
changed DATETIME,
|
||||||
|
PRIMARY KEY (change_id)
|
||||||
|
)
|
||||||
CREATE TABLE states (
|
CREATE TABLE states (
|
||||||
state_id INTEGER NOT NULL,
|
state_id INTEGER NOT NULL,
|
||||||
domain VARCHAR(64),
|
domain VARCHAR(64),
|
||||||
entity_id VARCHAR(64),
|
entity_id VARCHAR(255),
|
||||||
state VARCHAR(255),
|
state VARCHAR(255),
|
||||||
attributes TEXT,
|
attributes TEXT,
|
||||||
event_id INTEGER,
|
event_id INTEGER,
|
||||||
last_changed DATETIME,
|
last_changed DATETIME,
|
||||||
last_updated DATETIME,
|
last_updated DATETIME,
|
||||||
created DATETIME,
|
created DATETIME,
|
||||||
|
context_id VARCHAR(36),
|
||||||
|
context_user_id VARCHAR(36), context_parent_id CHARACTER(36), old_state_id INTEGER,
|
||||||
PRIMARY KEY (state_id),
|
PRIMARY KEY (state_id),
|
||||||
FOREIGN KEY(event_id) REFERENCES events (event_id)
|
FOREIGN KEY(event_id) REFERENCES events (event_id)
|
||||||
)
|
)
|
||||||
CREATE INDEX states__significant_changes ON states (domain, last_updated, entity_id)
|
|
||||||
CREATE INDEX states__state_changes ON states (last_changed, last_updated, entity_id)
|
|
||||||
CREATE TABLE sqlite_stat1(tbl,idx,stat)
|
CREATE TABLE sqlite_stat1(tbl,idx,stat)
|
||||||
|
CREATE INDEX ix_events_context_user_id ON events (context_user_id)
|
||||||
|
CREATE INDEX ix_events_event_type ON events (event_type)
|
||||||
|
CREATE INDEX ix_events_context_id ON events (context_id)
|
||||||
|
CREATE INDEX ix_events_time_fired ON events (time_fired)
|
||||||
|
CREATE INDEX ix_recorder_runs_start_end ON recorder_runs (start, "end")
|
||||||
|
CREATE INDEX ix_states_entity_id ON states (entity_id)
|
||||||
|
CREATE INDEX ix_states_context_user_id ON states (context_user_id)
|
||||||
|
CREATE INDEX ix_states_last_updated ON states (last_updated)
|
||||||
|
CREATE INDEX ix_states_event_id ON states (event_id)
|
||||||
|
CREATE INDEX ix_states_entity_id_last_updated ON states (entity_id, last_updated)
|
||||||
|
CREATE INDEX ix_states_context_id ON states (context_id)
|
||||||
|
CREATE INDEX ix_states_context_parent_id ON states (context_parent_id)
|
||||||
|
CREATE INDEX ix_events_context_parent_id ON events (context_parent_id)
|
||||||
```
|
```
|
||||||
|
|
||||||
To only show the details about the `states` table (since we are using that one in the next examples):
|
To only show the details about the `states` table (since we are using that one in the next examples):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user