Update database schema for v8 schema (#13784)

This commit is contained in:
J. Nick Koston 2020-06-19 13:41:32 -05:00 committed by GitHub
parent 1530e60036
commit 1a14367b24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,40 +41,60 @@ sqlite> SELECT sql FROM sqlite_master;
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------
CREATE TABLE events ( CREATE TABLE events (
event_id INTEGER NOT NULL, event_id INTEGER NOT NULL,
event_type VARCHAR(32), event_type VARCHAR(32),
event_data TEXT, event_data TEXT,
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,
"end" DATETIME, "end" DATETIME,
closed_incorrect BOOLEAN, closed_incorrect BOOLEAN,
created DATETIME, created DATETIME,
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,
PRIMARY KEY (state_id), context_id VARCHAR(36),
context_user_id VARCHAR(36), context_parent_id CHARACTER(36), old_state_id INTEGER,
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):