UUID as Primary Key (Re. 4682)
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.5|
|Severity:||Normal||Keywords:||primary key, uuid|
|Cc:||hv@…||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Re Ticket 4682: The OP didn't just want to add a UUID field type, that much should be a reasonably straightforward change. The real idea is to be able to use UUIDs as the primary key, instead of an auto-incrementing integer field. There are cases where this is a much better solution (busy write-heavy databases, remote sync using disconnected or asynchronous datasets, and so on).
I'm interested how much fiddling under the hood this would require, but I imagine a PRIMARY_KEY_TYPE option in settings.py. Since one advantage is there is no need to query the database to get the next integer in the PK field, one can simply generate a UUID code-side. I haven't looked under the hood yet, but presumably somewhere there is code to get the next PK integer when creating a new row, which can be so tweaked to generate a UUID instead, before the insert (and including the PK field and its value in the INSERT statement).
Sorry to ramble but I'd be interested to help out with such a venture :-)
Change History (8)
comment:5 Changed 6 years ago by
comment:6 Changed 5 years ago by
|Triage Stage:||Unreviewed → Design decision needed|
|Version:||1.2 → 1.4|