From 57e207cff2db024a6a3406a876e41c08edd337dc Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Wed, 22 Jul 2026 07:25:35 -0400 Subject: [PATCH] fix(db): don't use STR_TO_DATE in a generated column MariaDB 12.3 enforces that STR_TO_DATE (which reads lc_time_names) cannot appear in a GENERATED ALWAYS AS clause, so migration 0098 failed with error 1901 and RomM could not start. Earlier releases up to 12.2 accepted it, which is why the problem only surfaced on 12.3. The gamelist value is already pinned to a fixed-width "YYYYMMDDThhmmss" by the regex guard, so it is reshaped into a canonical datetime literal with SUBSTRING/CONCAT and fed to the existing TIMESTAMPDIFF. Stored values and their time-zone independence are unchanged. Fixes #3873 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../0098_generated_metadata_columns.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/alembic/versions/0098_generated_metadata_columns.py b/backend/alembic/versions/0098_generated_metadata_columns.py index d800e5046..572f0456f 100644 --- a/backend/alembic/versions/0098_generated_metadata_columns.py +++ b/backend/alembic/versions/0098_generated_metadata_columns.py @@ -111,13 +111,30 @@ def _maria_first_release_date() -> str: f"AND {val} REGEXP '^[0-9]+$' THEN {cast}" ) gl = "JSON_UNQUOTE(JSON_EXTRACT(gamelist_metadata, '$.first_release_date'))" - # TIMESTAMPDIFF from the UTC epoch is pure calendar arithmetic, so (unlike - # UNIX_TIMESTAMP) the stored value does not depend on the session time zone. + # MariaDB rejects STR_TO_DATE in a GENERATED ALWAYS AS clause (it reads + # lc_time_names), so the fixed-width "YYYYMMDDThhmmss" string is reshaped + # into a canonical datetime literal instead. TIMESTAMPDIFF from the UTC + # epoch is pure calendar arithmetic, so (unlike UNIX_TIMESTAMP) the stored + # value does not depend on the session time zone. + parts = [ + f"SUBSTRING({gl}, 1, 4)", + "'-'", + f"SUBSTRING({gl}, 5, 2)", + "'-'", + f"SUBSTRING({gl}, 7, 2)", + "' '", + f"SUBSTRING({gl}, 10, 2)", + "':'", + f"SUBSTRING({gl}, 12, 2)", + "':'", + f"SUBSTRING({gl}, 14, 2)", + ] + gl_datetime = "CONCAT(" + ", ".join(parts) + ")" branches.append( f"WHEN JSON_CONTAINS_PATH(gamelist_metadata, 'one', '$.first_release_date') " f"AND {gl} NOT IN ('null', 'None', '0', '0.0') " f"AND {gl} REGEXP '^[0-9]{{8}}T[0-9]{{6}}$' " - f"THEN TIMESTAMPDIFF(SECOND, '1970-01-01 00:00:00', STR_TO_DATE({gl}, '%Y%m%dT%H%i%S')) * 1000" + f"THEN TIMESTAMPDIFF(SECOND, '1970-01-01 00:00:00', {gl_datetime}) * 1000" ) return "CASE\n " + "\n ".join(branches) + "\n ELSE NULL END"