def _create_engine_test(*args, **kwargs): """Test version of create_engine that initializes with old schema. This simulates an existing db with the old schema. """ importlib.import_module(SCHEMA_MODULE) old_models = sys.modules[SCHEMA_MODULE] engine = create_engine(*args, **kwargs) old_models.Base.metadata.create_all(engine) with Session(engine) as session: session.add( recorder.models.StatisticsRuns(start=statistics.get_start_time())) session.add( recorder.models.SchemaChanges( schema_version=old_models.SCHEMA_VERSION)) session.commit() return engine
def do_adhoc_statistics(hass: HomeAssistant, **kwargs: Any) -> None: """Trigger an adhoc statistics run.""" if not (start := kwargs.get("start")): start = statistics.get_start_time()