2626# pylint: disable=invalid-name
2727Base = declarative_base ()
2828
29- SCHEMA_VERSION = 12
29+ SCHEMA_VERSION = 13
3030
3131_LOGGER = logging .getLogger (__name__ )
3232
3939
4040ALL_TABLES = [TABLE_STATES , TABLE_EVENTS , TABLE_RECORDER_RUNS , TABLE_SCHEMA_CHANGES ]
4141
42+ DATETIME_TYPE = DateTime (timezone = True ).with_variant (
43+ mysql .DATETIME (timezone = True , fsp = 6 ), "mysql"
44+ )
45+ 4246
4347class Events (Base ): # type: ignore
4448 """Event history data."""
@@ -52,8 +56,8 @@ class Events(Base): # type: ignore
5256 event_type = Column (String (32 ))
5357 event_data = Column (Text ().with_variant (mysql .LONGTEXT , "mysql" ))
5458 origin = Column (String (32 ))
55- time_fired = Column (DateTime ( timezone = True ) , index = True )
56- created = Column (DateTime ( timezone = True ) , default = dt_util .utcnow )
59+ time_fired = Column (DATETIME_TYPE , index = True )
60+ created = Column (DATETIME_TYPE , default = dt_util .utcnow )
5761 context_id = Column (String (36 ), index = True )
5862 context_user_id = Column (String (36 ), index = True )
5963 context_parent_id = Column (String (36 ), index = True )
@@ -123,9 +127,9 @@ class States(Base): # type: ignore
123127 event_id = Column (
124128 Integer , ForeignKey ("events.event_id" , ondelete = "CASCADE" ), index = True
125129 )
126- last_changed = Column (DateTime ( timezone = True ) , default = dt_util .utcnow )
127- last_updated = Column (DateTime ( timezone = True ) , default = dt_util .utcnow , index = True )
128- created = Column (DateTime ( timezone = True ) , default = dt_util .utcnow )
130+ last_changed = Column (DATETIME_TYPE , default = dt_util .utcnow )
131+ last_updated = Column (DATETIME_TYPE , default = dt_util .utcnow , index = True )
132+ created = Column (DATETIME_TYPE , default = dt_util .utcnow )
129133 old_state_id = Column (
130134 Integer , ForeignKey ("states.state_id" , ondelete = "NO ACTION" ), index = True
131135 )
0 commit comments