Use BIGINT SQL type for ID columns (#123973)
Redo recorder ID migration from INT to BIGINT
This commit is contained in:
parent
6c01e4b99c
commit
a7bca9bcea
4 changed files with 26 additions and 8 deletions
|
@ -77,7 +77,7 @@ class LegacyBase(DeclarativeBase):
|
|||
"""Base class for tables, used for schema migration."""
|
||||
|
||||
|
||||
SCHEMA_VERSION = 45
|
||||
SCHEMA_VERSION = 47
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -1112,7 +1112,7 @@ class _SchemaVersion16Migrator(_SchemaVersionMigrator, target_version=16):
|
|||
# Version 16 changes settings for the foreign key constraint on
|
||||
# states.old_state_id. Dropping the constraint is not really correct
|
||||
# we should have recreated it instead. Recreating the constraint now
|
||||
# happens in the migration to schema version 45.
|
||||
# happens in the migration to schema version 47.
|
||||
_drop_foreign_key_constraints(
|
||||
self.session_maker, self.engine, TABLE_STATES, "old_state_id"
|
||||
)
|
||||
|
@ -1637,6 +1637,24 @@ class _SchemaVersion43Migrator(_SchemaVersionMigrator, target_version=43):
|
|||
)
|
||||
|
||||
|
||||
class _SchemaVersion44Migrator(_SchemaVersionMigrator, target_version=44):
|
||||
def _apply_update(self) -> None:
|
||||
"""Version specific update method."""
|
||||
# The changes in this version are identical to the changes in version
|
||||
# 46. We apply the same changes again because the migration code previously
|
||||
# swallowed errors which caused some users' databases to end up in an
|
||||
# undefined state after the migration.
|
||||
|
||||
|
||||
class _SchemaVersion45Migrator(_SchemaVersionMigrator, target_version=45):
|
||||
def _apply_update(self) -> None:
|
||||
"""Version specific update method."""
|
||||
# The changes in this version are identical to the changes in version
|
||||
# 47. We apply the same changes again because the migration code previously
|
||||
# swallowed errors which caused some users' databases to end up in an
|
||||
# undefined state after the migration.
|
||||
|
||||
|
||||
FOREIGN_COLUMNS = (
|
||||
(
|
||||
"events",
|
||||
|
@ -1669,7 +1687,7 @@ FOREIGN_COLUMNS = (
|
|||
)
|
||||
|
||||
|
||||
class _SchemaVersion44Migrator(_SchemaVersionMigrator, target_version=44):
|
||||
class _SchemaVersion46Migrator(_SchemaVersionMigrator, target_version=46):
|
||||
def _apply_update(self) -> None:
|
||||
"""Version specific update method."""
|
||||
# We skip this step for SQLITE, it doesn't have differently sized integers
|
||||
|
@ -1720,14 +1738,14 @@ class _SchemaVersion44Migrator(_SchemaVersionMigrator, target_version=44):
|
|||
)
|
||||
|
||||
|
||||
class _SchemaVersion45Migrator(_SchemaVersionMigrator, target_version=45):
|
||||
class _SchemaVersion47Migrator(_SchemaVersionMigrator, target_version=47):
|
||||
def _apply_update(self) -> None:
|
||||
"""Version specific update method."""
|
||||
# We skip this step for SQLITE, it doesn't have differently sized integers
|
||||
if self.engine.dialect.name == SupportedDialect.SQLITE:
|
||||
return
|
||||
|
||||
# Restore constraints dropped in migration to schema version 44
|
||||
# Restore constraints dropped in migration to schema version 46
|
||||
_restore_foreign_key_constraints(
|
||||
self.session_maker,
|
||||
self.engine,
|
||||
|
|
|
@ -215,7 +215,7 @@ async def test_database_migration_failed(
|
|||
# Test error handling in _modify_columns
|
||||
(12, "sqlalchemy.engine.base.Connection.execute", False, 1, 0),
|
||||
# Test error handling in _drop_foreign_key_constraints
|
||||
(44, "homeassistant.components.recorder.migration.DropConstraint", False, 2, 1),
|
||||
(46, "homeassistant.components.recorder.migration.DropConstraint", False, 2, 1),
|
||||
],
|
||||
)
|
||||
@pytest.mark.skip_on_db_engine(["sqlite"])
|
||||
|
|
|
@ -640,7 +640,7 @@ async def test_out_of_disk_space_while_removing_foreign_key(
|
|||
ix_states_event_id is removed from the states table.
|
||||
|
||||
Note that the test is somewhat forced; the states.event_id foreign key constraint is
|
||||
removed when migrating to schema version 44, inspecting the schema in
|
||||
removed when migrating to schema version 46, inspecting the schema in
|
||||
cleanup_legacy_states_event_ids is not likely to fail.
|
||||
"""
|
||||
importlib.import_module(SCHEMA_MODULE)
|
||||
|
@ -779,7 +779,7 @@ async def test_out_of_disk_space_while_removing_foreign_key(
|
|||
states_index_names = {index["name"] for index in states_indexes}
|
||||
assert instance.use_legacy_events_index is True
|
||||
# The states.event_id foreign key constraint was removed when
|
||||
# migration to schema version 44
|
||||
# migration to schema version 46
|
||||
assert (
|
||||
await instance.async_add_executor_job(
|
||||
_get_event_id_foreign_keys
|
||||
|
|
Loading…
Add table
Reference in a new issue