-
Notifications
You must be signed in to change notification settings - Fork 399
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
Add type to store UUIDs as binary (UUID_BINARY) #1917
Add type to store UUIDs as binary (UUID_BINARY) #1917
Conversation
f40ef10
to
e705c03
Compare
e705c03
to
1bfc5dd
Compare
Great work!
vs #1915 and My main question would be: Do we need to have different type names per DB? In other words: Ideally we define
and by default picks the best internal strategy by default for each ORM DB type supported. Is that something we can achieve? |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files@@ Coverage Diff @@
## master #1917 +/- ##
=============================================
- Coverage 88.44% 73.25% -15.20%
- Complexity 7854 7917 +63
=============================================
Files 224 227 +3
Lines 20988 21133 +145
=============================================
- Hits 18562 15480 -3082
- Misses 2426 5653 +3227
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Ok, now I think we should keep both types, as it allows to still use @dereuromark what do you think does that make sense? |
b9159bb
to
432f0d0
Compare
These should be in phpstan ignoreErrors list. |
1cc4f07
to
22ce8f7
Compare
I have added code for automatic migration between When changing from a binary column to a <column name="id" type="varchar" size="36" content="UUID" /> I had to change some overall behavior to get this working, my assumption is that these changes are useful:
With the test, I am becoming more confident that this might actually work. Let me know what you think! |
cf10857
to
716325d
Compare
b06ce1d
to
d227cd0
Compare
b088a40
to
8d95036
Compare
8d95036
to
4f89150
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
tests/Propel/Tests/Runtime/Util/UuidConverterMysqlCompatibilityTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets put cleanup into follow up PR
Nice work
This allows Propel to work with UUIDs stored in a binary data column like
BINARY(16)
in MySQL.To use it, the column type in
schema.xml
has to be set toUUID_BINARY
:In models, fields of that type will always contain the UUID as string, conversion between binary value and string is done during loading (in
hydrate()
) or saving (indoInsert()
orbuildCriteria()
fromdoUpdate()
). Similar conversion happens in thefindBy
methods in the query class.This is a different approach than planned in #1914, but I found it integrates better into Propel.
Per default, UUID conversion will swap some bytes around, in accordance with MySQL's
uuid_to_bin()
function. This allows better indexing for version-1 UUIDs. The default behavior can be changed inschema.xml
by setting the value ofUuidSwapFlag
in vendor information:Caveats:
UuidSwapFlag
currently does not trigger a migration at all (it should cause all existing UUIDs to be (un)swapped).select()
on the query class or manually setting a formatter likeSimpleArrayFormatter
, will leave UUIDs in their binary form and users have to convert them manually by callingUuidConverter::binToUuid($uuidData, $swapFlag)
(depending on PDO behavior for the underlying dbms, they will have to read the resource/stream into a string first by callingstream_get_contents($uuidData)
).UuidConverter::uuidToBin($uuid, $swapFlag)
.Realistically, this will take a brave user to test and give feedback.