anthonynsimon / timeflake Goto Github PK
View Code? Open in Web Editor NEWTimeflake is a 128-bit, roughly-ordered, URL-safe UUID.
Home Page: https://pypi.org/project/timeflake/
License: MIT License
Timeflake is a 128-bit, roughly-ordered, URL-safe UUID.
Home Page: https://pypi.org/project/timeflake/
License: MIT License
Is generated UUID sortable also?
UUIDField is build into Django and should therefore be preferred as it will likely increase compat with other third party libraries such as DRF.
See previous issue #8 .
However, doing a subclassing now would likely result in migration incompatible changes (as the db type may change and foreign key relations could point to this). This would justify a Major Version increase according to SemVer even if only the django extension would be affected.
So, imho, there are two options:
What do you think, @anthonynsimon ?
I have a minor aversion to using projects that don't include dates in their changelog - I tend to follow the keepachangelog spec on my own projects, Curious if this is something that could be followed in the future?
The invalid
key does not exist anymore. I got this error
File "/.../lib/python3.9/site-packages/timeflake/extensions/django/__init__.py", line 64, in to_python
self.error_messages["invalid"], code="invalid", params={"value": value},
KeyError: 'invalid'
Non-random object IDs have privacy issues. Developers need to learn about these before they choose to use non-random IDs over simple random IDs. How about adding a PRIVACY section to the readme?
Timeflake encodes the precise time that a user created an object. Timestamps in IDs can reveal:
When using TimeflakePrimaryKeyBinary
in a Django model, it is not compatible with DRF out of the box because of the above error message.
Something similar to how https://github.com/ulid/spec#specification would be appreciated.
Also would be interested in how the conversion between timeflake to UUID and back may work (e.g. what extra field needed for lossless conversion from UUID back to timeflake.
Also any NULL or MAX value available?
On a side note... I wonder why timeflake and ULID have fixed time precision and random ID length. Would it have made sense to allow for developers to adjust timestamp precision or random bit length (or even shrink it if they feel like it)?
If I'm speculating on what this may look like, this is what I would come up with.
<48b: Timestamp><Ext Timestamp>...<X Random bits><Ext Random>...
Extended Timestamp:
0bXXXX_XXX0 - Timestamp Extension Completed (X= Random Bits)
0bTTTT_TTT1 - Next Byte is extended sub milisecond precision timestamp
Extended Randomness:
0b0XXX_XXXX - No Change
0b1RRR_RRRR - Next Byte is extended randomness
Lets say you have the following model and want to add history tracking to each FooModel object:
from simple_history.models import HistoricalRecords
class FooModel(models.Model):
id = TimeflakePrimaryKeyBinary()
history = HistoricalRecords(
history_id_field=models.UUIDField(default=uuid.uuid4)
)
It generates the following error during makemigrations
:
venv/lib/python3.9/site-packages/timeflake/extensions/django/__init__.py", line 97, in deconstruct del kwargs["primary_key"] KeyError: 'primary_key'
However, I tried adding the following try/except around this code and the migration would generate without an issue:
Downside is that leads to this error when trying to execute the migration:
django.db.utils.ProgrammingError: multiple primary keys for table "requisition_data_historicalrequisitionmodel" are not allowed LINE 1: ...me" varchar(200) NULL, "history_id" uuid NOT NULL PRIMARY KE...
So at the end of the day any model that uses TimeflakePrimaryKeyBinary for a primary ky id
field is unable to track object history using https://django-simple-history.readthedocs.io/en/latest/ which is a deficit.
I can manually adjust the migration after the fact to "work" (i.e. be a charfied or uuid field etc with primary_key = False) but django will not honor the change and all subsequent makemigrations
commands will try to undo the changes.
Can this issue be investigated? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.