Skip to content

Commit 6d07cc8

Browse files
committed
WL10004: Document UUID generation
MySQL Document Store requires JSON collection documents to contain a _id column, which is used as the primary key and therefore must be unique across the entire collection/table. This worklog implements a document identifier generator based on RFC 4122 UUID format (version 1, variant 1), with a modification to match the requirement of a stable id prefix.
1 parent c1d4a6f commit 6d07cc8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/mysqlx/dbdoc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -55,7 +55,9 @@ def keys(self):
5555

5656
def ensure_id(self):
5757
if "_id" not in self.__dict__:
58-
self.__dict__["_id"] = uuid.uuid4().hex
58+
uuid1 = str(uuid.uuid1()).upper().split("-")
59+
uuid1.reverse()
60+
self.__dict__["_id"] = "".join(uuid1)
5961
return self.__dict__["_id"]
6062

6163
def __str__(self):

0 commit comments

Comments
 (0)