Skip to content

Fix timestamp/time type handling in diff and repair pipelines#78

Merged
mason-sharp merged 2 commits intomainfrom
fix/ACE-165/timestamp-without-tz
Feb 18, 2026
Merged

Fix timestamp/time type handling in diff and repair pipelines#78
mason-sharp merged 2 commits intomainfrom
fix/ACE-165/timestamp-without-tz

Conversation

@mason-sharp
Copy link
Member

  • Split combined timestamp/timestamptz case in ConvertToPgxType; return pgxv5type.Timestamp for "timestamp without time zone" so pgx sends the correct wire type
  • Add time/timetz support: serialize pgxv5type.Time in diff output, parse time strings back to pgxv5type.Time in ConvertToPgxType, and pass timetz as string (unregistered in pgx v5 type map)
  • Exclude "time with time zone" from IsKnownScalarType so the diff layer casts it to ::TEXT (avoids scan error on unregistered type)
  • Wrap time.Time in pgxv5type.Timestamp in repair's convertValueForType for timestamp-without-tz columns
  • Add unit tests for all new type handling paths
  • Add integration test exercising full diff→repair round-trip for all four temporal types

- Split combined timestamp/timestamptz case in ConvertToPgxType; return
  pgxv5type.Timestamp for "timestamp without time zone" so pgx sends
  the correct wire type
- Add time/timetz support: serialize pgxv5type.Time in diff output,
  parse time strings back to pgxv5type.Time in ConvertToPgxType, and
  pass timetz as string (unregistered in pgx v5 type map)
- Exclude "time with time zone" from IsKnownScalarType so the diff
  layer casts it to ::TEXT (avoids scan error on unregistered type)
- Wrap time.Time in pgxv5type.Timestamp in repair's convertValueForType
  for timestamp-without-tz columns
- Add unit tests for all new type handling paths
- Add integration test exercising full diff→repair round-trip for all
  four temporal types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

Adds handling and conversion for PostgreSQL temporal types (TIMESTAMP, TIMESTAMPTZ, TIME, TIMETZ) to diff and repair code paths, introduces parsing helpers for timestamps and times, and expands unit and integration tests to verify pgx v5 type wrapping and SQL generation.

Changes

Cohort / File(s) Summary
Diff formatting
internal/consistency/diff/table_diff.go
Formats pgx v5 Time values in fetchRows to HH:MM:SS.mmmmmm or nil when invalid.
Repair conversions
internal/consistency/repair/table_repair.go, internal/consistency/repair/table_repair_test.go
Wraps time.Time as pgxv5type.Timestamp{...} for "timestamp without time zone" in convertValueForType; adds tests validating wrapping, SQL generation, and value preservation across timestamp/time variants.
Common utils & helpers
pkg/common/utils.go, pkg/common/utils_test.go
Adds parseTimestampString and parseTimeToMicroseconds; enhances ConvertToPgxType to return pgxv5type.Timestamp/pgxv5type.Time for parsed inputs, with string fallbacks and validation. Expands tests for precision and format cases.
Integration test
tests/integration/table_repair_test.go
New end-to-end test TestTableRepair_TimestampAndTimeTypes to exercise diff→repair pipeline and validate temporal column synchronization across nodes.

Poem

🐇 I nibble timestamps, microseconds clear,
Wrap them gently so no TZ appears,
HH:MM:SS, neat as a row,
Diff and repair and onward we go,
A rabbit's cheer for temporal cheer!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the primary change: fixing timestamp and time type handling across diff and repair pipelines, which is the core focus of all changes in the PR.
Description check ✅ Passed The description is directly related to the changeset, providing specific implementation details that align with the summary of changes across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/ACE-165/timestamp-without-tz

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/common/utils.go`:
- Around line 28-29: parseTimeToMicroseconds currently accepts out-of-range
hour/minute/second values and fractional seconds with more than 6 digits; update
parseTimeToMicroseconds to validate that hour is 0–23, minute and second are
0–59 (or explicitly document/handle leap-second 60 if desired), reject
non-numeric components, and return an error for invalid ranges. For fractional
seconds, accept up to 6 digits by truncating (not rounding) extra digits or
padding with zeros to 6 digits before converting to microseconds, and ensure the
final microsecond count is computed from validated parts; make these checks and
truncation inside parseTimeToMicroseconds and propagate an error instead of
silently producing incorrect values.

Reject out-of-range hours (>23), minutes (>59), and seconds (>59).
Truncate fractional second digits beyond 6 to microsecond precision.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/common/utils_test.go (1)

131-168: Consider asserting parsed time values in format/precision tests.

TestConvertToPgxType_TimestampWithPrecision and TestConvertToPgxType_TimestampFormats verify that the correct type is returned and Valid == true, but don't assert the actual parsed Time field. For the precision test this is fine, but for the formats test, asserting known expected values for at least one or two cases would catch silent mis-parses (e.g., a format that parses "10:30" as "00:00" and still returns Valid: true).

Not blocking — the current tests still add meaningful coverage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/common/utils_test.go` around lines 131 - 168, Update the timestamp tests
to assert actual parsed time values in addition to type/Valid checks: in
TestConvertToPgxType_TimestampWithPrecision and
TestConvertToPgxType_TimestampFormats call ConvertToPgxType (already used) then
cast to pgxv5type.Timestamp and compare ts.Time (or ts.Time.UTC()) to expected
time.Time values for at least one or two formats (e.g., the "RFC3339" case and
one offset/space-separated case) using time.Equal or UTC-normalized equality;
keep the existing type and Valid assertions and fail the test if the parsed time
does not match the expected value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/common/utils_test.go`:
- Around line 131-168: Update the timestamp tests to assert actual parsed time
values in addition to type/Valid checks: in
TestConvertToPgxType_TimestampWithPrecision and
TestConvertToPgxType_TimestampFormats call ConvertToPgxType (already used) then
cast to pgxv5type.Timestamp and compare ts.Time (or ts.Time.UTC()) to expected
time.Time values for at least one or two formats (e.g., the "RFC3339" case and
one offset/space-separated case) using time.Equal or UTC-normalized equality;
keep the existing type and Valid assertions and fail the test if the parsed time
does not match the expected value.

@mason-sharp mason-sharp merged commit 1e26207 into main Feb 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant