Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 725cadb

Browse files
author
Sergey Vasilyev
committed
Preserve lower-/upper-case mode of UUIDs and render them back accordingly
1 parent 6949367 commit 725cadb

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

data_diff/abcs/database_types.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,14 @@ class Native_UUID(ColType_UUID):
217217

218218
@attrs.define(frozen=True)
219219
class String_UUID(ColType_UUID, StringType):
220-
pass
220+
# Case is important for UUIDs stored as regular string, not native UUIDs stored as numbers.
221+
# We slice them internally as numbers, but render them back to SQL as lower/upper case.
222+
# None means we do not know for sure, behave as with False, but it might be unreliable.
223+
lowercase: Optional[bool] = None
224+
uppercase: Optional[bool] = None
225+
226+
def make_value(self, v: str) -> ArithUUID:
227+
return self.python_type(v, lowercase=self.lowercase, uppercase=self.uppercase)
221228

222229

223230
@attrs.define(frozen=True)

data_diff/databases/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def _compile(self, compiler: Compiler, elem) -> str:
250250
return f"b'{elem.decode()}'"
251251
elif isinstance(elem, ArithUUID):
252252
s = f"'{elem.uuid}'"
253-
return s
253+
return s.upper() if elem.uppercase else s.lower() if elem.lowercase else s
254254
elif isinstance(elem, ArithString):
255255
return f"'{elem}'"
256256
assert False, elem
@@ -1115,7 +1115,10 @@ def _refine_coltypes(
11151115
)
11161116
else:
11171117
assert col_name in col_dict
1118-
col_dict[col_name] = String_UUID()
1118+
col_dict[col_name] = String_UUID(
1119+
lowercase=all(s == s.lower() for s in uuid_samples),
1120+
uppercase=all(s == s.upper() for s in uuid_samples),
1121+
)
11191122
continue
11201123

11211124
if self.SUPPORTS_ALPHANUMS: # Anything but MySQL (so far)

data_diff/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class ArithUUID(ArithString):
151151
"A UUID that supports basic arithmetic (add, sub)"
152152

153153
uuid: UUID = attrs.field(converter=_any_to_uuid)
154+
lowercase: Optional[bool] = None
155+
uppercase: Optional[bool] = None
156+
154157
def range(self, other: "ArithUUID", count: int) -> List[Self]:
155158
assert isinstance(other, ArithUUID)
156159
checkpoints = split_space(self.uuid.int, other.uuid.int, count)

0 commit comments

Comments
 (0)