[recorder] Index events time_fired to improve logbook performance (#5633)

* Index events time_fired to improve logbook perf.

* Updated implementation to track schema versions

* Added tests for schema migration support logic

* Rename check_schema to migrate_schema
This commit is contained in:
Adam Mills authored and GitHub committed 2017-02-02 22:04:14 -05:00
1 parent dfb991ce19
commit 6a64e79d7b
3 files changed
+110 -1

No files matched your search

+12 -1
View File
@@ -16,6 +16,8 @@ from homeassistant.remote import JSONEncoder
# pylint: disable=invalid-name
Base = declarative_base()
SCHEMA_VERSION = 1
_LOGGER = logging.getLogger(__name__)
@@ -27,7 +29,7 @@ class Events(Base): # type: ignore
event_type = Column(String(32), index=True)
event_data = Column(Text)
origin = Column(String(32))
time_fired = Column(DateTime(timezone=True))
time_fired = Column(DateTime(timezone=True), index=True)
created = Column(DateTime(timezone=True), default=datetime.utcnow)
@staticmethod
@@ -149,6 +151,15 @@ class RecorderRuns(Base): # type: ignore
return self
class SchemaChanges(Base): # type: ignore
"""Representation of schema version changes."""
__tablename__ = 'schema_changes'
change_id = Column(Integer, primary_key=True)
schema_version = Column(Integer)
changed = Column(DateTime(timezone=True), default=datetime.utcnow)
def _process_timestamp(ts):
"""Process a timestamp into datetime object."""
if ts is None: