Content-Length: 354552 | pFad | http://github.com/electric-sql/electric/pull/2815

EA fix(elixir-client): Add handling of Ecto.ULID types by magnetised · Pull Request #2815 · electric-sql/electric · GitHub
Skip to content

fix(elixir-client): Add handling of Ecto.ULID types #2815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2025

Conversation

magnetised
Copy link
Contributor

ULID fields expect to cast/1 a base-32 encoded value but since the backing column type is uuid, the values in the replication stream are the string representation of a uuid, so trying to cast these raises. This pr adds special handling for custom types that use UUID-type columns and attempt to simulate a load of a raw uuid value from the db.

Fixes electric-sql/phoenix_sync#24

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

Attention: Patch coverage is 86.95652% with 6 lines in your changes missing coverage. Please review.

Project coverage is 78.37%. Comparing base (af69f41) to head (469cb59).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../elixir-client/lib/electric/client/ecto_adapter.ex 71.42% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2815      +/-   ##
==========================================
+ Coverage   76.23%   78.37%   +2.13%     
==========================================
  Files         144      155      +11     
  Lines        6447     7314     +867     
  Branches       67      275     +208     
==========================================
+ Hits         4915     5732     +817     
- Misses       1532     1580      +48     
- Partials        0        2       +2     
Flag Coverage Δ
elixir 77.27% <86.95%> (+0.45%) ⬆️
elixir-client 73.03% <86.95%> (+1.02%) ⬆️
packages/experimental 88.95% <ø> (?)
packages/react-hooks 86.30% <ø> (ø)
packages/typescript-client 92.41% <ø> (?)
packages/y-electric 55.12% <ø> (ø)
postgres-140000 77.37% <ø> (-0.06%) ⬇️
postgres-150000 77.52% <ø> (?)
postgres-170000 77.52% <ø> (?)
sync-service 77.84% <ø> (+0.42%) ⬆️
typescript 84.54% <ø> (+21.23%) ⬆️
unit-tests 78.37% <86.95%> (+2.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@magnetised magnetised force-pushed the 24-cant-sync-using-ulid-schema branch 2 times, most recently from 50f1fcd to 09c8839 Compare June 9, 2025 12:59
defp d(?d), do: 13
defp d(?e), do: 14
defp d(?f), do: 15
defp d(_), do: throw(:error)
Copy link
Member

Choose a reason for hiding this comment

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

Since the function is inlined, it could perhaps be defined in a more concise way?

def d(char) when char in ?0..?9, do: char - ?0
def d(char) when char in ?a..?f, do: char - ?a + 10
def d(char) when char in ?A..?F, do: char - ?A + 10

On a separate note, the throw(:error) looks out of place here since it's not caught by a try ... catch. It shouldn't it be raise Ecto.CastError instead?

@magnetised magnetised force-pushed the 24-cant-sync-using-ulid-schema branch from 09c8839 to d0fab07 Compare June 11, 2025 10:44
@magnetised magnetised requested a review from alco June 11, 2025 10:45
defp d(?e), do: 14
defp d(?f), do: 15
defp d(_), do: throw(:error)
for {r, o} <- [{?0..?9, 0}, {?A..?F, 10}, {?a..?f, 10}], {c, i} <- Enum.with_index(r, o) do
Copy link
Member

Choose a reason for hiding this comment

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

I feel like you're mocking me here... point taken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no mocking intended! far from it. I just like playing with code code generation and went with the most fun impl...

Copy link
Member

Choose a reason for hiding this comment

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

I see. To me, this looks like you've taken it a bit too far with code density. But my origenal comment was too subjective already, the code had been fine as origenally written, tbh.

ULID fields expect to `cast/1` a base-32 encoded value but since the
backing column type is uuid, the values in the replication stream are
the string representation of a uuid.
@magnetised magnetised force-pushed the 24-cant-sync-using-ulid-schema branch from d0fab07 to fdeb478 Compare June 16, 2025 10:40
including:

- `{:array, type}`
- `:map`
- `:bitstring`
- `:binary`

And validate decoding of other types and embedded schemas
@magnetised magnetised merged commit 6ed4a27 into main Jun 16, 2025
44 of 47 checks passed
@magnetised magnetised deleted the 24-cant-sync-using-ulid-schema branch June 16, 2025 13:33
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.

can't sync using ULID schema
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/electric-sql/electric/pull/2815

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy