Functions | |
| None | _add_columns (Callable[[], Session] session_maker, str table_name, list[str] columns_def) |
| None | _add_constraint (Callable[[], Session] session_maker, AddConstraint add_constraint, str table, str column) |
| None | _apply_update (Recorder instance, HomeAssistant hass, Engine engine, Callable[[], Session] session_maker, int new_version, int old_version) |
| bytes|None | _context_id_to_bytes (str|None context_id) |
| None | _correct_table_character_set_and_collation (str table, Callable[[], Session] session_maker) |
| None | _create_index (Callable[[], Session] session_maker, str table_name, str index_name) |
| None | _delete_foreign_key_violations (Callable[[], Session] session_maker, Engine engine, str table, str column, str foreign_table, str foreign_column) |
| None | _drop_foreign_key_constraints (Callable[[], Session] session_maker, Engine engine, str table, str column) |
| None | _drop_index (Callable[[], Session] session_maker, str table_name, str index_name, bool|None quiet=None) |
| bool | _execute_or_collect_error (Callable[[], Session] session_maker, str query, list[str] errors) |
| set[str] | _find_schema_errors (HomeAssistant hass, Recorder instance, Callable[[], Session] session_maker) |
| bytes | _generate_ulid_bytes_at_time (float|None timestamp) |
| dict[str, int] | _get_migration_changes (Session session) |
| int|None | _get_schema_version (Session session) |
| bool | _initialize_database (Session session) |
| None | _mark_migration_done (Session session, type[BaseMigration] migration) |
| None | _migrate_columns_to_timestamp (Recorder instance, Callable[[], Session] session_maker, Engine engine) |
| SchemaValidationStatus | _migrate_schema (Recorder instance, HomeAssistant hass, Engine engine, Callable[[], Session] session_maker, SchemaValidationStatus schema_status, int end_version) |
| None | _migrate_statistics_columns_to_timestamp (Recorder instance, Callable[[], Session] session_maker, Engine engine) |
| None | _migrate_statistics_columns_to_timestamp_one_by_one (Recorder instance, Callable[[], Session] session_maker) |
| None | _migrate_statistics_columns_to_timestamp_removing_duplicates (HomeAssistant hass, Recorder instance, Callable[[], Session] session_maker, Engine engine) |
| None | _modify_columns (Callable[[], Session] session_maker, Engine engine, str table_name, list[str] columns_def) |
| None | _restore_foreign_key_constraints (Callable[[], Session] session_maker, Engine engine, list[tuple[str, str, str|None, str|None]] foreign_columns) |
| bool | _schema_is_current (int current_version) |
| None | _update_states_table_with_foreign_key_options (Callable[[], Session] session_maker, Engine engine) |
| None | _wipe_old_string_time_columns (Recorder instance, Engine engine, Session session) |
| int|None | get_schema_version (Callable[[], Session] session_maker) |
| bool | initialize_database (Callable[[], Session] session_maker) |
| bool | live_migration (SchemaValidationStatus schema_status) |
| None | migrate_data_live (Recorder instance, Callable[[], Session] session_maker, SchemaValidationStatus schema_status) |
| None | migrate_data_non_live (Recorder instance, Callable[[], Session] session_maker, SchemaValidationStatus schema_status) |
| SchemaValidationStatus | migrate_schema_live (Recorder instance, HomeAssistant hass, Engine engine, Callable[[], Session] session_maker, SchemaValidationStatus schema_status) |
| SchemaValidationStatus | migrate_schema_non_live (Recorder instance, HomeAssistant hass, Engine engine, Callable[[], Session] session_maker, SchemaValidationStatus schema_status) |
| bool | non_live_data_migration_needed (Recorder instance, Callable[[], Session] session_maker, int schema_version) |
| bool | post_migrate_entity_ids (Recorder instance) |
| None | pre_migrate_schema (Engine engine) |
| None | raise_if_exception_missing_str (Exception ex, Iterable[str] match_substrs) |
| bool | rebuild_sqlite_table (Callable[[], Session] session_maker, Engine engine, type[Base] table) |
| SchemaValidationStatus|None | validate_db_schema (HomeAssistant hass, Recorder instance, Callable[[], Session] session_maker) |
Variables | |
| string | _EMPTY_ENTITY_ID = "missing.entity_id" |
| string | _EMPTY_EVENT_TYPE = "missing_event_type" |
| _LOGGER = logging.getLogger(__name__) | |
| _MYSQL_COLUMN_TYPES | |
| _POSTGRESQL_COLUMN_TYPES | |
| _SQLITE_COLUMN_TYPES | |
| tuple | FOREIGN_COLUMNS |
| tuple | LIVE_DATA_MIGRATORS |
| int | LIVE_MIGRATION_MIN_SCHEMA_VERSION = 42 |
| tuple | MIGRATION_NOTE_MINUTES |
| tuple | MIGRATION_NOTE_OFFLINE |
| string | MIGRATION_NOTE_WHILE = "This will take a while; please be patient!" |
| tuple | NON_LIVE_DATA_MIGRATORS |
Schema migration helpers.
|
private |
Add columns to a table.
Definition at line 540 of file migration.py.
|
private |
Add a foreign key constraint.
Definition at line 790 of file migration.py.
|
private |
Perform operations to bring schema up to date.
Definition at line 927 of file migration.py.
|
private |
Convert a context_id to bytes.
Definition at line 2166 of file migration.py.
|
private |
Correct issues detected by validate_db_schema.
Definition at line 1873 of file migration.py.
|
private |
Create an index for the specified table. The index name should match the name given for the index within the table definition described in the models
Definition at line 430 of file migration.py.
|
private |
Remove rows which violate the constraints.
Definition at line 813 of file migration.py.
|
private |
Drop foreign key constraints for a table on specific columns. This is not supported for SQLite because it does not support dropping constraints.
Definition at line 699 of file migration.py.
|
private |
Drop an index from a specified table. There is no universal way to do something like `DROP INDEX IF EXISTS` so we will simply execute the DROP command and ignore any exceptions WARNING: Due to some engines (MySQL at least) being unable to use bind parameters in a DROP INDEX statement (at least via SQLAlchemy), the query string here is generated from the method parameters without sanitizing. DO NOT USE THIS FUNCTION IN ANY OPERATION THAT TAKES USER INPUT.
Definition at line 479 of file migration.py.
|
private |
Execute a query or collect an error.
Definition at line 466 of file migration.py.
|
private |
Find schema errors.
Definition at line 253 of file migration.py.
|
private |
Generate a ulid with a specific timestamp.
Definition at line 2182 of file migration.py.
|
private |
Return migration changes as a dict.
Definition at line 368 of file migration.py.
|
private |
Get the schema version.
Definition at line 183 of file migration.py.
|
private |
Initialize a new database. The function determines the schema version by inspecting the db structure. When the schema version is not present in the db, either db was just created with the correct schema, or this is a db created before schema versions were tracked. For now, we'll test if the changes for schema version 1 are present to make the determination. Eventually this logic can be removed and we can assume a new db is being created.
Definition at line 2205 of file migration.py.
|
private |
Mark a migration as done in the database.
Definition at line 2773 of file migration.py.
|
private |
Migrate columns to use timestamp.
Definition at line 1956 of file migration.py.
|
private |
Check if the schema needs to be upgraded.
Definition at line 289 of file migration.py.
|
private |
Migrate statistics columns to use timestamp.
Definition at line 2098 of file migration.py.
|
private |
Migrate statistics columns to use timestamp on by one. If something manually inserted data into the statistics table in the past it may have inserted duplicate rows. Before we had the unique index on (statistic_id, start) this the data could have been inserted without any errors and we could end up with duplicate rows that go undetected (even by our current duplicate cleanup code) until we try to migrate the data to use timestamps. This will migrate the data one by one to ensure we do not hit any duplicate rows, and remove the duplicate rows as they are found.
Definition at line 2045 of file migration.py.
|
private |
Migrate statistics columns to timestamp or cleanup duplicates.
Definition at line 1838 of file migration.py.
|
private |
Modify columns in a table.
Definition at line 580 of file migration.py.
|
private |
Restore foreign key constraints.
Definition at line 737 of file migration.py.
|
private |
Check if the schema is current.
Definition at line 214 of file migration.py.
|
private |
Add the options to foreign key constraints. This is not supported for SQLite because it does not support dropping constraints.
Definition at line 639 of file migration.py.
|
private |
Wipe old string time columns to save space.
Definition at line 1901 of file migration.py.
| int | None homeassistant.components.recorder.migration.get_schema_version | ( | Callable[[], Session] | session_maker | ) |
Get the schema version.
Definition at line 193 of file migration.py.
| bool homeassistant.components.recorder.migration.initialize_database | ( | Callable[[], Session] | session_maker | ) |
Initialize a new database.
Definition at line 2232 of file migration.py.
| bool homeassistant.components.recorder.migration.live_migration | ( | SchemaValidationStatus | schema_status | ) |
Check if live migration is possible.
Definition at line 264 of file migration.py.
| None homeassistant.components.recorder.migration.migrate_data_live | ( | Recorder | instance, |
| Callable[[], Session] | session_maker, | ||
| SchemaValidationStatus | schema_status | ||
| ) |
Queue live schema migration tasks. This must be called after live schema migration is completed.
Definition at line 413 of file migration.py.
| None homeassistant.components.recorder.migration.migrate_data_non_live | ( | Recorder | instance, |
| Callable[[], Session] | session_maker, | ||
| SchemaValidationStatus | schema_status | ||
| ) |
Do non-live data migration. This must be called after non-live schema migration is completed.
Definition at line 396 of file migration.py.
| SchemaValidationStatus homeassistant.components.recorder.migration.migrate_schema_live | ( | Recorder | instance, |
| HomeAssistant | hass, | ||
| Engine | engine, | ||
| Callable[[], Session] | session_maker, | ||
| SchemaValidationStatus | schema_status | ||
| ) |
Check if the schema needs to be upgraded.
Definition at line 342 of file migration.py.
| SchemaValidationStatus homeassistant.components.recorder.migration.migrate_schema_non_live | ( | Recorder | instance, |
| HomeAssistant | hass, | ||
| Engine | engine, | ||
| Callable[[], Session] | session_maker, | ||
| SchemaValidationStatus | schema_status | ||
| ) |
Check if the schema needs to be upgraded.
Definition at line 328 of file migration.py.
| bool homeassistant.components.recorder.migration.non_live_data_migration_needed | ( | Recorder | instance, |
| Callable[[], Session] | session_maker, | ||
| int | schema_version | ||
| ) |
Return True if non-live data migration is needed. This must only be called if database schema is current.
Definition at line 377 of file migration.py.
| bool homeassistant.components.recorder.migration.post_migrate_entity_ids | ( | Recorder | instance | ) |
Remove old entity_id strings from states. We cannot do this in migrate_entity_ids since the history queries still need to work while the migration is in progress.
Definition at line 2187 of file migration.py.
| None homeassistant.components.recorder.migration.pre_migrate_schema | ( | Engine | engine | ) |
Prepare for migration. This function is called before calling Base.metadata.create_all.
Definition at line 272 of file migration.py.
| None homeassistant.components.recorder.migration.raise_if_exception_missing_str | ( | Exception | ex, |
| Iterable[str] | match_substrs | ||
| ) |
Raise if the exception and cause do not contain the match substrs.
Definition at line 172 of file migration.py.
| bool homeassistant.components.recorder.migration.rebuild_sqlite_table | ( | Callable[[], Session] | session_maker, |
| Engine | engine, | ||
| type[Base] | table | ||
| ) |
Rebuild an SQLite table. This must only be called after all migrations are complete and the database is in a consistent state. If the table is not migrated to the current schema this will likely fail.
Definition at line 2782 of file migration.py.
| SchemaValidationStatus | None homeassistant.components.recorder.migration.validate_db_schema | ( | HomeAssistant | hass, |
| Recorder | instance, | ||
| Callable[[], Session] | session_maker | ||
| ) |
Check if the schema is valid. This checks that the schema is the current version as well as for some common schema errors caused by manual migration between database engines, for example importing an SQLite database to MariaDB.
Definition at line 219 of file migration.py.
|
private |
Definition at line 134 of file migration.py.
|
private |
Definition at line 135 of file migration.py.
|
private |
Definition at line 137 of file migration.py.
|
private |
Definition at line 147 of file migration.py.
|
private |
Definition at line 153 of file migration.py.
|
private |
Definition at line 159 of file migration.py.
| tuple homeassistant.components.recorder.migration.FOREIGN_COLUMNS |
Definition at line 1736 of file migration.py.
| tuple homeassistant.components.recorder.migration.LIVE_DATA_MIGRATORS |
Definition at line 2766 of file migration.py.
| int homeassistant.components.recorder.migration.LIVE_MIGRATION_MIN_SCHEMA_VERSION = 42 |
Definition at line 121 of file migration.py.
| tuple homeassistant.components.recorder.migration.MIGRATION_NOTE_MINUTES |
Definition at line 128 of file migration.py.
| tuple homeassistant.components.recorder.migration.MIGRATION_NOTE_OFFLINE |
Definition at line 123 of file migration.py.
| string homeassistant.components.recorder.migration.MIGRATION_NOTE_WHILE = "This will take a while; please be patient!" |
Definition at line 132 of file migration.py.
| tuple homeassistant.components.recorder.migration.NON_LIVE_DATA_MIGRATORS |
Definition at line 2761 of file migration.py.