Skip to content

Conversation

@simolus3
Copy link
Contributor

@simolus3 simolus3 commented Nov 7, 2025

Extracting sub-millisecond accuracy out of MySQL will require powersync-ja/powersync-mysql-zongji#15, so this is WIP.

This adds the timestamp_max_precision option for the config block when defining sync rules. Valid options are seconds, milliseconds and microseconds. Restricting precision is convenient in some cases, e.g. when other parts of an app can't handle sub-millisecond precision (something we noticed for some users migrating to edition: 2 which pads postgres timestamps to six digits).

When a source database provides a time value, it now also provides:

  • The inner precision of that time value (milliseconds for mongo, micros for mysql and postgres). That doesn't mean that every value has that many fractional digits (postgres could e.g. emit 11:03:00.000000 as 11:03:00), but it reflects the maximum precision supported.
  • A default precision to use when no max precision is configured on sync rules. This matches the inner precision for mongo and postgres. For mysql, we use milliseconds as the default precision for backwards compatibility, while supporting microseconds as an opt-in.

Depending on compatibility options, a time value is then formatted with a precision of min(timestamp_max_precision ?? source.default_precision, source.inner_precision). We also pad values to ensure we consistently use the same amount of digits.

@changeset-bot
Copy link

changeset-bot bot commented Nov 7, 2025

⚠️ No Changeset found

Latest commit: ba06ea1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

2 participants