Skip to content
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

Provide UuidMixin for consistent use of UUIDs as non-primary keys #123

Closed
8 of 11 tasks
jace opened this issue Jun 16, 2017 · 1 comment
Closed
8 of 11 tasks

Provide UuidMixin for consistent use of UUIDs as non-primary keys #123

jace opened this issue Jun 16, 2017 · 1 comment

Comments

@jace
Copy link
Member

jace commented Jun 16, 2017

Several of our apps have evolved use of UUIDs, but in their own ways:

  1. DocTypeHTML5 began the tradition of using Base64 UUIDs, but with a custom alphabet.
  2. Lastuser introduced them as the userid column, also standardising on URL-safe Base64 encoding, henceforth known as the buid encoding.
  3. Flask-Lastuser has a corresponding userid column in its mixins.
  4. Eventframe uses buid encoding in a column named uuid.
  5. Nodular uses buid encoding in a column named buid.
  6. Imgee uses hex encoding in a column named name.
  7. Hasjob uses native UUID storage for the session object, in a column named uuid.

These varied usages need to be standardised. While IdMixin introduced support for UUID primary keys in 1d2d315, we have many cases where the app is not ready to migrate to UUIDs for primary keys, and only needs them for secondary (but unique) keys.

Following the lessons from #112, #114 and #121, we could introduce a UuidMixin that offers a standard interface:

  1. A uuid column that stores a native UUID and auto-generates it on first access (as in Auto-set UUID on first access #112 for IdMixin).
  2. A buid hybrid attribute that proxies to the native UUID storage (as in Move url_id from BaseIdNameMixin to BaseMixin or IdMixin #114).
  3. An suuid hybrid attribute that does likewise (as in Add buid and suuid hybrid attributes and update url_name #121).
  4. Optional: a url_id hybrid attribute (as in Move url_id from BaseIdNameMixin to BaseMixin or IdMixin #114).

The hybrid attributes in this UuidMixin will clash with the ones provided by IdMixin in #121. The assumptions for use therefore are:

  1. A class using UuidMixin gives it priority by using the UuidMixin, BaseMixin, db.Model order for base classes.
  2. This class must not use UUID primary keys.
  3. Migrations (database and code references) will be necessary for each of the apps listed above.
jace added a commit to hasgeek/hasjob that referenced this issue Jun 20, 2017
This will need revisiting with hasgeek/coaster#123 though.
jace added a commit that referenced this issue Jun 20, 2017
@jace
Copy link
Member Author

jace commented Jun 20, 2017

The implementation in #124 uses @declared_attr to make uuid a column if the main class uses integer primary keys, else an alias to the existing id UUID column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant