Skip to content

Conversation

@techouse
Copy link
Owner

@techouse techouse commented Nov 16, 2025

This pull request improves the handling of default values when converting SQLite schemas to MySQL, specifically by enhancing the translation of SQLite timestamp expressions that use current_timestamp within date/time functions. The changes ensure that expressions like datetime(current_timestamp, ...) are correctly mapped to the appropriate MySQL equivalents, addressing cases that were previously missed.

Key changes include:

Enhancements to Timestamp Expression Handling:

  • Added a new regex pattern SQLITE_CURRENT_TS_FUNC to match SQLite expressions such as datetime(current_timestamp, ...), allowing for more accurate detection and translation of these defaults.
  • Updated the logic in _translate_default_for_mysql to detect when the default value uses datetime, date, or time functions with current_timestamp, and map them to the correct MySQL expressions (CURRENT_TIMESTAMP, UTC_TIMESTAMP, etc.) for TIMESTAMP, DATETIME, DATE, and TIME columns. [1] [2] [3] [4] [5]

Testing Improvements:

  • Added new unit tests to verify that SQLite defaults like datetime(current_timestamp, 'localtime') and datetime(current_timestamp, 'utc') are properly converted to CURRENT_TIMESTAMP and UTC_TIMESTAMP (with precision, if specified) in MySQL.

Partially fixes #154

@techouse techouse self-assigned this Nov 16, 2025
@techouse techouse added the bug Something isn't working label Nov 16, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 16, 2025

Walkthrough

The pull request extends SQLite-to-MySQL default value translation by introducing a regex pattern to detect current_timestamp() function variants and enhancements to the translation logic to handle localtime/utc modifiers and preserve fractional seconds in TIMESTAMP, DATETIME, DATE, and TIME default values.

Changes

Cohort / File(s) Change Summary
Production — Default translation enhancements
src/sqlite3_to_mysql/transporter.py
Added class-level regex pattern SQLITE_CURRENT_TS_FUNC to detect current_timestamp() variants. Extended _translate_default_for_mysql() to detect current_timestamp expressions and route them through appropriate MySQL equivalents (CURRENT_TIMESTAMP, UTC_TIMESTAMP) while preserving fractional seconds and respecting localtime/utc modifiers.
Test coverage — New datetime test cases
tests/unit/sqlite3_to_mysql_test.py
Added two new parameterised test cases: DATETIME without precision using current_timestamp (localtime path) mapping to CURRENT_TIMESTAMP, and DATETIME(3) with current_timestamp and 'utc' modifier mapping to UTC_TIMESTAMP(3).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Regex pattern correctness: Verify the SQLITE_CURRENT_TS_FUNC pattern accurately captures all current_timestamp() variants with optional modifiers.
  • Conditional branch logic: Review the extended conditional paths for TIMESTAMP/DATETIME/DATE/TIME to ensure all modifier and fractional-second combinations are handled correctly.
  • Edge cases: Confirm handling of nested or malformed current_timestamp() expressions and boundary conditions with precision values.

Possibly related PRs

Poem

A rabbit hops through timestamp fields,
With current_timestamp calls,
Detecting modifiers—utc and local yields,
Translating defaults through MySQL's halls. 🐰⏰
Fractional seconds preserved with care,
New paths for datetime everywhere!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change—enhancing translation of SQLite timestamp expressions using current_timestamp—directly matching the pull request's core objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description comprehensively covers all required sections: it summarises the changes, explains the motivation (improving timestamp handling), lists key enhancements and testing improvements, and provides context on the specific issue being addressed.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/datetime-defaults

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.05%. Comparing base (c69c712) to head (e703708).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #157   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files           8        8           
  Lines        1129     1132    +3     
=======================================
+ Hits         1107     1110    +3     
  Misses         22       22           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@techouse techouse merged commit 0a876c7 into master Nov 16, 2025
74 checks passed
@techouse techouse deleted the fix/datetime-defaults branch November 16, 2025 15:29
@techouse techouse added this to the 2.5.5 milestone Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Following CREATE TABLE conversion fails because of multiple problems

2 participants