Skip to content

Commit 29ce9c7

Browse files
authored
🐛 handle curtime(), curdate(), current_timestamp(), and now() MariaDB-specific translations in default values (#100)
1 parent 1a0f401 commit 29ce9c7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/mysql_to_sqlite3/transporter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ def _translate_default_from_mysql_to_sqlite(
326326
return "DEFAULT(FALSE)"
327327
return f"DEFAULT '{int(column_default)}'"
328328
if isinstance(column_default, str):
329+
if column_default.lower() == "curtime()":
330+
return "DEFAULT CURRENT_TIME"
331+
if column_default.lower() == "curdate()":
332+
return "DEFAULT CURRENT_DATE"
333+
if column_default.lower() in {"current_timestamp()", "now()"}:
334+
return "DEFAULT CURRENT_TIMESTAMP"
329335
if column_extra in {"DEFAULT_GENERATED", "default_generated"}:
330336
if column_default.upper() in {
331337
"CURRENT_TIME",

tests/unit/mysql_to_sqlite3_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ def test_translate_type_from_mysql_to_sqlite_all_valid_columns(self) -> None:
113113
),
114114
pytest.param("CURRENT_TIME", "DEFAULT_GENERATED", "DEFAULT CURRENT_TIME", id='"CURRENT_TIME"'),
115115
pytest.param("current_time", "DEFAULT_GENERATED", "DEFAULT CURRENT_TIME", id='"current_time"'),
116+
pytest.param("curtime()", None, "DEFAULT CURRENT_TIME", id='"curtime()"'),
116117
pytest.param("CURRENT_DATE", "DEFAULT_GENERATED", "DEFAULT CURRENT_DATE", id='"CURRENT_DATE"'),
117118
pytest.param("current_date", "DEFAULT_GENERATED", "DEFAULT CURRENT_DATE", id='"current_date"'),
119+
pytest.param("curdate()", None, "DEFAULT CURRENT_DATE", id='"curdate()"'),
118120
pytest.param(
119121
"CURRENT_TIMESTAMP",
120122
"DEFAULT_GENERATED",
@@ -127,6 +129,8 @@ def test_translate_type_from_mysql_to_sqlite_all_valid_columns(self) -> None:
127129
"DEFAULT CURRENT_TIMESTAMP",
128130
id='"current_timestamp"',
129131
),
132+
pytest.param("current_timestamp()", None, "DEFAULT CURRENT_TIMESTAMP", id='"current_timestamp()"'),
133+
pytest.param("now()", None, "DEFAULT CURRENT_TIMESTAMP", id='"now()"'),
130134
pytest.param(r"""_utf8mb4\'[]\'""", "DEFAULT_GENERATED", "DEFAULT '[]'", id=r"""_utf8mb4\'[]\'"""),
131135
pytest.param(r"""_latin1\'abc\'""", "DEFAULT_GENERATED", "DEFAULT 'abc'", id=r"""_latin1\'abc\'"""),
132136
pytest.param(r"""_binary\'abc\'""", "DEFAULT_GENERATED", "DEFAULT 'abc'", id=r"""_binary\'abc\'"""),

0 commit comments

Comments
 (0)