Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.recorder.db_schema Namespace Reference

Classes

class  _StatisticsMeta
 
class  _StatisticsShortTerm
 
class  Base
 
class  EventData
 
class  Events
 
class  EventTypes
 
class  FAST_PYSQLITE_DATETIME
 
class  JSONLiteral
 
class  LegacyBase
 
class  LegacyStatisticsMeta
 
class  LegacyStatisticsShortTerm
 
class  MigrationChanges
 
class  NativeLargeBinary
 
class  RecorderRuns
 
class  SchemaChanges
 
class  StateAttributes
 
class  States
 
class  StatesMeta
 
class  Statistics
 
class  StatisticsBase
 
class  StatisticsMeta
 
class  StatisticsRuns
 
class  StatisticsShortTerm
 
class  Unused
 
class  UnusedDateTime
 

Functions

str compile_char_one (TypeDecorator type_, Any compiler, **Any kw)
 
str compile_char_zero (TypeDecorator type_, Any compiler, **Any kw)
 

Variables

dictionary _DEFAULT_TABLE_ARGS
 
 _LOGGER = logging.getLogger(__name__)
 
dictionary _MATCH_ALL_KEEP
 
list ALL_TABLES
 
string BIG_INTEGER_SQL = "BIGINT"
 
 ColumnElement
 
 CONTEXT_BINARY_TYPE
 
int CONTEXT_ID_BIN_MAX_LENGTH = 16
 
tuple DATETIME_TYPE
 
string DOUBLE_PRECISION_TYPE_SQL = "DOUBLE PRECISION"
 
tuple DOUBLE_TYPE
 
 EVENT_DATA_JSON
 
list EVENT_ORIGIN_ORDER = [EventOrigin.local, EventOrigin.remote]
 
string EVENTS_CONTEXT_ID_BIN_INDEX = "ix_events_context_id_bin"
 
 ID_TYPE = BigInteger().with_variant(sqlite.INTEGER, "sqlite")
 
 JSON_VARIANT_CAST
 
 JSONB_VARIANT_CAST
 
string LAST_UPDATED_INDEX_TS = "ix_states_last_updated_ts"
 
string LEGACY_STATES_ENTITY_ID_LAST_UPDATED_INDEX = "ix_states_entity_id_last_updated_ts"
 
string LEGACY_STATES_EVENT_ID_INDEX = "ix_states_event_id"
 
int MAX_EVENT_DATA_BYTES = 32768
 
int MAX_STATE_ATTRS_BYTES = 16384
 
string METADATA_ID_LAST_UPDATED_INDEX_TS = "ix_states_metadata_id_last_updated_ts"
 
string MYSQL_COLLATE = "utf8mb4_unicode_ci"
 
string MYSQL_DEFAULT_CHARSET = "utf8mb4"
 
string MYSQL_ENGINE = "InnoDB"
 
 OLD_FORMAT_ATTRS_JSON
 
 OLD_FORMAT_EVENT_DATA_JSON
 
 OLD_STATE = aliased(States, name="old_state")
 
 PSQL_DIALECT = SupportedDialect.POSTGRESQL
 
int SCHEMA_VERSION = 47
 
 SHARED_ATTR_OR_LEGACY_ATTRIBUTES
 
 SHARED_ATTRS_JSON
 
 SHARED_DATA_OR_LEGACY_EVENT_DATA
 
string STATES_CONTEXT_ID_BIN_INDEX = "ix_states_context_id_bin"
 
tuple STATISTICS_TABLES = ("statistics", "statistics_short_term")
 
string TABLE_EVENT_DATA = "event_data"
 
string TABLE_EVENT_TYPES = "event_types"
 
string TABLE_EVENTS = "events"
 
string TABLE_MIGRATION_CHANGES = "migration_changes"
 
string TABLE_RECORDER_RUNS = "recorder_runs"
 
string TABLE_SCHEMA_CHANGES = "schema_changes"
 
string TABLE_STATE_ATTRIBUTES = "state_attributes"
 
string TABLE_STATES = "states"
 
string TABLE_STATES_META = "states_meta"
 
string TABLE_STATISTICS = "statistics"
 
string TABLE_STATISTICS_META = "statistics_meta"
 
string TABLE_STATISTICS_RUNS = "statistics_runs"
 
string TABLE_STATISTICS_SHORT_TERM = "statistics_short_term"
 
list TABLES_TO_CHECK
 
tuple TIMESTAMP_TYPE = DOUBLE_TYPE
 
 UINT_32_TYPE
 
 UNUSED_LEGACY_COLUMN = Unused(0)
 
 UNUSED_LEGACY_DATETIME_COLUMN = UnusedDateTime(timezone=True)
 
 UNUSED_LEGACY_INTEGER_COLUMN = SmallInteger()
 

Detailed Description

Models for SQLAlchemy.

Function Documentation

◆ compile_char_one()

str homeassistant.components.recorder.db_schema.compile_char_one ( TypeDecorator  type_,
Any  compiler,
**Any  kw 
)
Compile Unused as CHAR(1) on postgresql.

Definition at line 173 of file db_schema.py.

◆ compile_char_zero()

str homeassistant.components.recorder.db_schema.compile_char_zero ( TypeDecorator  type_,
Any  compiler,
**Any  kw 
)
Compile UnusedDateTime and Unused as CHAR(0) on mysql, mariadb, and sqlite.

Definition at line 167 of file db_schema.py.

Variable Documentation

◆ _DEFAULT_TABLE_ARGS

dictionary homeassistant.components.recorder.db_schema._DEFAULT_TABLE_ARGS
private
Initial value:
1 = {
2  "mysql_default_charset": MYSQL_DEFAULT_CHARSET,
3  "mysql_collate": MYSQL_COLLATE,
4  "mysql_engine": MYSQL_ENGINE,
5  "mariadb_default_charset": MYSQL_DEFAULT_CHARSET,
6  "mariadb_collate": MYSQL_COLLATE,
7  "mariadb_engine": MYSQL_ENGINE,
8 }

Definition at line 140 of file db_schema.py.

◆ _LOGGER

homeassistant.components.recorder.db_schema._LOGGER = logging.getLogger(__name__)
private

Definition at line 82 of file db_schema.py.

◆ _MATCH_ALL_KEEP

dictionary homeassistant.components.recorder.db_schema._MATCH_ALL_KEEP
private
Initial value:
1 = {
2  ATTR_DEVICE_CLASS,
3  ATTR_STATE_CLASS,
4  ATTR_UNIT_OF_MEASUREMENT,
5  ATTR_FRIENDLY_NAME,
6 }

Definition at line 149 of file db_schema.py.

◆ ALL_TABLES

list homeassistant.components.recorder.db_schema.ALL_TABLES
Initial value:
1 = [
2  TABLE_STATES,
3  TABLE_STATE_ATTRIBUTES,
4  TABLE_EVENTS,
5  TABLE_EVENT_DATA,
6  TABLE_EVENT_TYPES,
7  TABLE_RECORDER_RUNS,
8  TABLE_SCHEMA_CHANGES,
9  TABLE_MIGRATION_CHANGES,
10  TABLE_STATES_META,
11  TABLE_STATISTICS,
12  TABLE_STATISTICS_META,
13  TABLE_STATISTICS_RUNS,
14  TABLE_STATISTICS_SHORT_TERM,
15 ]

Definition at line 105 of file db_schema.py.

◆ BIG_INTEGER_SQL

string homeassistant.components.recorder.db_schema.BIG_INTEGER_SQL = "BIGINT"

Definition at line 227 of file db_schema.py.

◆ ColumnElement

homeassistant.components.recorder.db_schema.ColumnElement

Definition at line 920 of file db_schema.py.

◆ CONTEXT_BINARY_TYPE

homeassistant.components.recorder.db_schema.CONTEXT_BINARY_TYPE
Initial value:
1 = LargeBinary(CONTEXT_ID_BIN_MAX_LENGTH).with_variant(
2  NativeLargeBinary(CONTEXT_ID_BIN_MAX_LENGTH), "mysql", "mariadb", "sqlite"
3 )

Definition at line 228 of file db_schema.py.

◆ CONTEXT_ID_BIN_MAX_LENGTH

int homeassistant.components.recorder.db_schema.CONTEXT_ID_BIN_MAX_LENGTH = 16

Definition at line 134 of file db_schema.py.

◆ DATETIME_TYPE

tuple homeassistant.components.recorder.db_schema.DATETIME_TYPE
Initial value:
1 = (
2  DateTime(timezone=True)
3  .with_variant(mysql.DATETIME(timezone=True, fsp=6), "mysql", "mariadb") # type: ignore[no-untyped-call]
4  .with_variant(FAST_PYSQLITE_DATETIME(), "sqlite") # type: ignore[no-untyped-call]
5 )

Definition at line 212 of file db_schema.py.

◆ DOUBLE_PRECISION_TYPE_SQL

string homeassistant.components.recorder.db_schema.DOUBLE_PRECISION_TYPE_SQL = "DOUBLE PRECISION"

Definition at line 226 of file db_schema.py.

◆ DOUBLE_TYPE

tuple homeassistant.components.recorder.db_schema.DOUBLE_TYPE
Initial value:
1 = (
2  Float()
3  .with_variant(mysql.DOUBLE(asdecimal=False), "mysql", "mariadb") # type: ignore[no-untyped-call]
4  .with_variant(oracle.DOUBLE_PRECISION(), "oracle")
5  .with_variant(postgresql.DOUBLE_PRECISION(), "postgresql")
6 )

Definition at line 217 of file db_schema.py.

◆ EVENT_DATA_JSON

homeassistant.components.recorder.db_schema.EVENT_DATA_JSON
Initial value:
1 = type_coerce(
2  EventData.shared_data.cast(JSONB_VARIANT_CAST), JSONLiteral(none_as_null=True)
3 )

Definition at line 906 of file db_schema.py.

◆ EVENT_ORIGIN_ORDER

list homeassistant.components.recorder.db_schema.EVENT_ORIGIN_ORDER = [EventOrigin.local, EventOrigin.remote]

Definition at line 248 of file db_schema.py.

◆ EVENTS_CONTEXT_ID_BIN_INDEX

string homeassistant.components.recorder.db_schema.EVENTS_CONTEXT_ID_BIN_INDEX = "ix_events_context_id_bin"

Definition at line 130 of file db_schema.py.

◆ ID_TYPE

homeassistant.components.recorder.db_schema.ID_TYPE = BigInteger().with_variant(sqlite.INTEGER, "sqlite")

Definition at line 196 of file db_schema.py.

◆ JSON_VARIANT_CAST

homeassistant.components.recorder.db_schema.JSON_VARIANT_CAST
Initial value:
1 = Text().with_variant(
2  postgresql.JSON(none_as_null=True), # type: ignore[no-untyped-call]
3  "postgresql",
4 )

Definition at line 204 of file db_schema.py.

◆ JSONB_VARIANT_CAST

homeassistant.components.recorder.db_schema.JSONB_VARIANT_CAST
Initial value:
1 = Text().with_variant(
2  postgresql.JSONB(none_as_null=True), # type: ignore[no-untyped-call]
3  "postgresql",
4 )

Definition at line 208 of file db_schema.py.

◆ LAST_UPDATED_INDEX_TS

string homeassistant.components.recorder.db_schema.LAST_UPDATED_INDEX_TS = "ix_states_last_updated_ts"

Definition at line 128 of file db_schema.py.

◆ LEGACY_STATES_ENTITY_ID_LAST_UPDATED_INDEX

string homeassistant.components.recorder.db_schema.LEGACY_STATES_ENTITY_ID_LAST_UPDATED_INDEX = "ix_states_entity_id_last_updated_ts"

Definition at line 133 of file db_schema.py.

◆ LEGACY_STATES_EVENT_ID_INDEX

string homeassistant.components.recorder.db_schema.LEGACY_STATES_EVENT_ID_INDEX = "ix_states_event_id"

Definition at line 132 of file db_schema.py.

◆ MAX_EVENT_DATA_BYTES

int homeassistant.components.recorder.db_schema.MAX_EVENT_DATA_BYTES = 32768

Definition at line 101 of file db_schema.py.

◆ MAX_STATE_ATTRS_BYTES

int homeassistant.components.recorder.db_schema.MAX_STATE_ATTRS_BYTES = 16384

Definition at line 100 of file db_schema.py.

◆ METADATA_ID_LAST_UPDATED_INDEX_TS

string homeassistant.components.recorder.db_schema.METADATA_ID_LAST_UPDATED_INDEX_TS = "ix_states_metadata_id_last_updated_ts"

Definition at line 129 of file db_schema.py.

◆ MYSQL_COLLATE

string homeassistant.components.recorder.db_schema.MYSQL_COLLATE = "utf8mb4_unicode_ci"

Definition at line 136 of file db_schema.py.

◆ MYSQL_DEFAULT_CHARSET

string homeassistant.components.recorder.db_schema.MYSQL_DEFAULT_CHARSET = "utf8mb4"

Definition at line 137 of file db_schema.py.

◆ MYSQL_ENGINE

string homeassistant.components.recorder.db_schema.MYSQL_ENGINE = "InnoDB"

Definition at line 138 of file db_schema.py.

◆ OLD_FORMAT_ATTRS_JSON

homeassistant.components.recorder.db_schema.OLD_FORMAT_ATTRS_JSON
Initial value:
1 = type_coerce(
2  States.attributes.cast(JSON_VARIANT_CAST), JSON(none_as_null=True)
3 )

Definition at line 916 of file db_schema.py.

◆ OLD_FORMAT_EVENT_DATA_JSON

homeassistant.components.recorder.db_schema.OLD_FORMAT_EVENT_DATA_JSON
Initial value:
1 = type_coerce(
2  Events.event_data.cast(JSONB_VARIANT_CAST), JSONLiteral(none_as_null=True)
3 )

Definition at line 909 of file db_schema.py.

◆ OLD_STATE

homeassistant.components.recorder.db_schema.OLD_STATE = aliased(States, name="old_state")

Definition at line 923 of file db_schema.py.

◆ PSQL_DIALECT

homeassistant.components.recorder.db_schema.PSQL_DIALECT = SupportedDialect.POSTGRESQL

Definition at line 103 of file db_schema.py.

◆ SCHEMA_VERSION

int homeassistant.components.recorder.db_schema.SCHEMA_VERSION = 47

Definition at line 80 of file db_schema.py.

◆ SHARED_ATTR_OR_LEGACY_ATTRIBUTES

homeassistant.components.recorder.db_schema.SHARED_ATTR_OR_LEGACY_ATTRIBUTES
Initial value:
1 = case(
2  (StateAttributes.shared_attrs.is_(None), States.attributes),
3  else_=StateAttributes.shared_attrs,
4 ).label("attributes")

Definition at line 925 of file db_schema.py.

◆ SHARED_ATTRS_JSON

homeassistant.components.recorder.db_schema.SHARED_ATTRS_JSON
Initial value:
1 = type_coerce(
2  StateAttributes.shared_attrs.cast(JSON_VARIANT_CAST), JSON(none_as_null=True)
3 )

Definition at line 913 of file db_schema.py.

◆ SHARED_DATA_OR_LEGACY_EVENT_DATA

homeassistant.components.recorder.db_schema.SHARED_DATA_OR_LEGACY_EVENT_DATA
Initial value:
1 = case(
2  (EventData.shared_data.is_(None), Events.event_data), else_=EventData.shared_data
3 ).label("event_data")

Definition at line 929 of file db_schema.py.

◆ STATES_CONTEXT_ID_BIN_INDEX

string homeassistant.components.recorder.db_schema.STATES_CONTEXT_ID_BIN_INDEX = "ix_states_context_id_bin"

Definition at line 131 of file db_schema.py.

◆ STATISTICS_TABLES

tuple homeassistant.components.recorder.db_schema.STATISTICS_TABLES = ("statistics", "statistics_short_term")

Definition at line 98 of file db_schema.py.

◆ TABLE_EVENT_DATA

string homeassistant.components.recorder.db_schema.TABLE_EVENT_DATA = "event_data"

Definition at line 85 of file db_schema.py.

◆ TABLE_EVENT_TYPES

string homeassistant.components.recorder.db_schema.TABLE_EVENT_TYPES = "event_types"

Definition at line 86 of file db_schema.py.

◆ TABLE_EVENTS

string homeassistant.components.recorder.db_schema.TABLE_EVENTS = "events"

Definition at line 84 of file db_schema.py.

◆ TABLE_MIGRATION_CHANGES

string homeassistant.components.recorder.db_schema.TABLE_MIGRATION_CHANGES = "migration_changes"

Definition at line 96 of file db_schema.py.

◆ TABLE_RECORDER_RUNS

string homeassistant.components.recorder.db_schema.TABLE_RECORDER_RUNS = "recorder_runs"

Definition at line 90 of file db_schema.py.

◆ TABLE_SCHEMA_CHANGES

string homeassistant.components.recorder.db_schema.TABLE_SCHEMA_CHANGES = "schema_changes"

Definition at line 91 of file db_schema.py.

◆ TABLE_STATE_ATTRIBUTES

string homeassistant.components.recorder.db_schema.TABLE_STATE_ATTRIBUTES = "state_attributes"

Definition at line 88 of file db_schema.py.

◆ TABLE_STATES

string homeassistant.components.recorder.db_schema.TABLE_STATES = "states"

Definition at line 87 of file db_schema.py.

◆ TABLE_STATES_META

string homeassistant.components.recorder.db_schema.TABLE_STATES_META = "states_meta"

Definition at line 89 of file db_schema.py.

◆ TABLE_STATISTICS

string homeassistant.components.recorder.db_schema.TABLE_STATISTICS = "statistics"

Definition at line 92 of file db_schema.py.

◆ TABLE_STATISTICS_META

string homeassistant.components.recorder.db_schema.TABLE_STATISTICS_META = "statistics_meta"

Definition at line 93 of file db_schema.py.

◆ TABLE_STATISTICS_RUNS

string homeassistant.components.recorder.db_schema.TABLE_STATISTICS_RUNS = "statistics_runs"

Definition at line 94 of file db_schema.py.

◆ TABLE_STATISTICS_SHORT_TERM

string homeassistant.components.recorder.db_schema.TABLE_STATISTICS_SHORT_TERM = "statistics_short_term"

Definition at line 95 of file db_schema.py.

◆ TABLES_TO_CHECK

list homeassistant.components.recorder.db_schema.TABLES_TO_CHECK
Initial value:
1 = [
2  TABLE_STATES,
3  TABLE_EVENTS,
4  TABLE_RECORDER_RUNS,
5  TABLE_SCHEMA_CHANGES,
6 ]

Definition at line 121 of file db_schema.py.

◆ TIMESTAMP_TYPE

tuple homeassistant.components.recorder.db_schema.TIMESTAMP_TYPE = DOUBLE_TYPE

Definition at line 232 of file db_schema.py.

◆ UINT_32_TYPE

homeassistant.components.recorder.db_schema.UINT_32_TYPE
Initial value:
1 = BigInteger().with_variant(
2  mysql.INTEGER(unsigned=True), # type: ignore[no-untyped-call]
3  "mysql",
4  "mariadb",
5 )

Definition at line 199 of file db_schema.py.

◆ UNUSED_LEGACY_COLUMN

homeassistant.components.recorder.db_schema.UNUSED_LEGACY_COLUMN = Unused(0)

Definition at line 223 of file db_schema.py.

◆ UNUSED_LEGACY_DATETIME_COLUMN

homeassistant.components.recorder.db_schema.UNUSED_LEGACY_DATETIME_COLUMN = UnusedDateTime(timezone=True)

Definition at line 224 of file db_schema.py.

◆ UNUSED_LEGACY_INTEGER_COLUMN

homeassistant.components.recorder.db_schema.UNUSED_LEGACY_INTEGER_COLUMN = SmallInteger()

Definition at line 225 of file db_schema.py.