tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

Support UUIDs in ORM

Open brendt opened this issue 1 year ago • 2 comments

  • Postgres has the UUID type: https://www.postgresql.org/docs/current/datatype-uuid.html
  • MySQL advices to store UUIDs as binary values because of index performance: https://dev.mysql.com/blog-archive/storing-uuid-values-in-mysql-tables/
  • SQLite could use BLOB to store the binary representation

In case we need to convert from UUID to binary (MySQL and SQLite), the easiest way to do it would be in PHP:

  • That way we don't have to worry about special inserts per database-dialect.
  • Selecting should be done using the binary format of the UUID, so we'd have to convert it before building the select query
  • The CreateTableStatement and AlterTableStatement should simply have a uuid() method that creates the field with a unique index
  • We might have an option to store the "human readable" version in the database as well

An example of how this was done with a Laravel package (before Laravel had support for it): https://github.com/spatie/laravel-binary-uuid/tree/master

Having thought it through, I think we're in the clear about breaking changes, and can move this to post-1.0

brendt avatar Oct 24 '24 19:10 brendt

Just adding, it would be good if the UUID supported was specifically UUIDv7 so it's sortable https://uuid7.com - coming from Laravel I've been using ULID for the advantages, but UUIDv7 makes ULID unnecessary and obviously there's wider support then.

iamdadmin avatar May 17 '25 07:05 iamdadmin

Wrongly closed this one, sorry

brendt avatar Oct 04 '25 12:10 brendt