Fix statistics schema µs precision auto repair being ineffective (#89902)
If a user manually migrated their database to MySQL or PostgresSQL and incorrectly created the timestamp columns as float we would fail to correct them to double because when we migrated to use timestamps for the columns I missed that we needed to change the columns and types for µs precisionpull/89973/head
parent
e798c30b8b
commit
d33a303a83
|
@ -2590,8 +2590,8 @@ def _validate_db_schema(
|
|||
for column in columns:
|
||||
if stored[column] != expected[column]:
|
||||
schema_errors.add(f"{table_name}.{supports}")
|
||||
_LOGGER.debug(
|
||||
"Column %s in database table %s does not support %s (%s != %s)",
|
||||
_LOGGER.error(
|
||||
"Column %s in database table %s does not support %s (stored=%s != expected=%s)",
|
||||
column,
|
||||
table_name,
|
||||
supports,
|
||||
|
@ -2727,18 +2727,14 @@ def correct_db_schema(
|
|||
],
|
||||
)
|
||||
if f"{table.__tablename__}.µs precision" in schema_errors:
|
||||
# Attempt to convert datetime columns to µs precision
|
||||
if instance.dialect_name == SupportedDialect.MYSQL:
|
||||
datetime_type = "DATETIME(6)"
|
||||
else:
|
||||
datetime_type = "TIMESTAMP(6) WITH TIME ZONE"
|
||||
# Attempt to convert timestamp columns to µs precision
|
||||
_modify_columns(
|
||||
session_maker,
|
||||
engine,
|
||||
table.__tablename__,
|
||||
[
|
||||
f"last_reset {datetime_type}",
|
||||
f"start {datetime_type}",
|
||||
"last_reset_ts DOUBLE PRECISION",
|
||||
"start_ts DOUBLE PRECISION",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -1687,12 +1687,12 @@ async def test_validate_db_schema_fix_float_issue(
|
|||
@pytest.mark.parametrize(
|
||||
("db_engine", "modification"),
|
||||
(
|
||||
("mysql", ["last_reset DATETIME(6)", "start DATETIME(6)"]),
|
||||
("mysql", ["last_reset_ts DOUBLE PRECISION", "start_ts DOUBLE PRECISION"]),
|
||||
(
|
||||
"postgresql",
|
||||
[
|
||||
"last_reset TIMESTAMP(6) WITH TIME ZONE",
|
||||
"start TIMESTAMP(6) WITH TIME ZONE",
|
||||
"last_reset_ts DOUBLE PRECISION",
|
||||
"start_ts DOUBLE PRECISION",
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue