From e52eea3a1a24c08c8b21ce45c2ac12adcf9f3f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Thu, 3 Jul 2025 20:52:03 +0100 Subject: [PATCH 1/3] :bug: handle curtime(), curdate(), and, current_timestamp() and now() MariaDB specific translations in default values --- src/mysql_to_sqlite3/transporter.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mysql_to_sqlite3/transporter.py b/src/mysql_to_sqlite3/transporter.py index e98f842..efe93fc 100644 --- a/src/mysql_to_sqlite3/transporter.py +++ b/src/mysql_to_sqlite3/transporter.py @@ -326,6 +326,12 @@ def _translate_default_from_mysql_to_sqlite( return "DEFAULT(FALSE)" return f"DEFAULT '{int(column_default)}'" if isinstance(column_default, str): + if column_default.lower() == "curtime()": + return f"DEFAULT CURRENT_TIME" + if column_default.lower() == "curdate()": + return f"DEFAULT CURRENT_DATE" + if column_default.lower() in {"current_timestamp()", "now()"}: + return f"DEFAULT CURRENT_TIMESTAMP" if column_extra in {"DEFAULT_GENERATED", "default_generated"}: if column_default.upper() in { "CURRENT_TIME", From b454fc1faba5710241296ff77732352131c913c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Thu, 3 Jul 2025 20:52:13 +0100 Subject: [PATCH 2/3] :white_check_mark: add tests for curtime(), curdate(), current_timestamp(), and now() translations in default values --- tests/unit/mysql_to_sqlite3_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/mysql_to_sqlite3_test.py b/tests/unit/mysql_to_sqlite3_test.py index 6685738..6e0c4d7 100644 --- a/tests/unit/mysql_to_sqlite3_test.py +++ b/tests/unit/mysql_to_sqlite3_test.py @@ -113,8 +113,10 @@ def test_translate_type_from_mysql_to_sqlite_all_valid_columns(self) -> None: ), pytest.param("CURRENT_TIME", "DEFAULT_GENERATED", "DEFAULT CURRENT_TIME", id='"CURRENT_TIME"'), pytest.param("current_time", "DEFAULT_GENERATED", "DEFAULT CURRENT_TIME", id='"current_time"'), + pytest.param("curtime()", None, "DEFAULT CURRENT_TIME", id='"curtime()"'), pytest.param("CURRENT_DATE", "DEFAULT_GENERATED", "DEFAULT CURRENT_DATE", id='"CURRENT_DATE"'), pytest.param("current_date", "DEFAULT_GENERATED", "DEFAULT CURRENT_DATE", id='"current_date"'), + pytest.param("curdate()", None, "DEFAULT CURRENT_DATE", id='"curdate()"'), pytest.param( "CURRENT_TIMESTAMP", "DEFAULT_GENERATED", @@ -127,6 +129,8 @@ def test_translate_type_from_mysql_to_sqlite_all_valid_columns(self) -> None: "DEFAULT CURRENT_TIMESTAMP", id='"current_timestamp"', ), + pytest.param("current_timestamp()", None, "DEFAULT CURRENT_TIMESTAMP", id='"current_timestamp()"'), + pytest.param("now()", None, "DEFAULT CURRENT_TIMESTAMP", id='"now()"'), pytest.param(r"""_utf8mb4\'[]\'""", "DEFAULT_GENERATED", "DEFAULT '[]'", id=r"""_utf8mb4\'[]\'"""), pytest.param(r"""_latin1\'abc\'""", "DEFAULT_GENERATED", "DEFAULT 'abc'", id=r"""_latin1\'abc\'"""), pytest.param(r"""_binary\'abc\'""", "DEFAULT_GENERATED", "DEFAULT 'abc'", id=r"""_binary\'abc\'"""), From 0f774fc60dc3325e6ea79922460313ae35e9f01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Tu=C5=A1ar?= Date: Thu, 3 Jul 2025 20:55:49 +0100 Subject: [PATCH 3/3] :rotating_light: remove redundant f-strings in default value translations for MariaDB functions --- src/mysql_to_sqlite3/transporter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mysql_to_sqlite3/transporter.py b/src/mysql_to_sqlite3/transporter.py index efe93fc..f5fdf01 100644 --- a/src/mysql_to_sqlite3/transporter.py +++ b/src/mysql_to_sqlite3/transporter.py @@ -327,11 +327,11 @@ def _translate_default_from_mysql_to_sqlite( return f"DEFAULT '{int(column_default)}'" if isinstance(column_default, str): if column_default.lower() == "curtime()": - return f"DEFAULT CURRENT_TIME" + return "DEFAULT CURRENT_TIME" if column_default.lower() == "curdate()": - return f"DEFAULT CURRENT_DATE" + return "DEFAULT CURRENT_DATE" if column_default.lower() in {"current_timestamp()", "now()"}: - return f"DEFAULT CURRENT_TIMESTAMP" + return "DEFAULT CURRENT_TIMESTAMP" if column_extra in {"DEFAULT_GENERATED", "default_generated"}: if column_default.upper() in { "CURRENT_TIME",