Conversation
|
Hey @alvaroMaleno really appreciate your efforts here. Just wondering though how this differs from adding an extra UUID field to the DB models? if it’s not reversible anyways to get the model from uuid there doesn’t seem to be a difference. Instead of decrypting we’d just do a database lookup by uuid. Thanks |
|
Hello @TreyWW . The idea here is to add an extra layer. When an entity is retrieved from db a new calculated field public_id or somewhat would be assigned with the get_uuid method in execution time. Parameters would be: id, name_of_the_model. Later, when the client request via GET or any operation that entity with the public id, in execution time the app would be able to recover the numeric id merely callig to the method revert. Any other operation would remain unchanged in the subsequent steps.
|
|
Perhaps an example could be much clarifier than texting @TreyWW |
Description
Title: Add deterministic, reversible UUID helper for model IDs
This PR introduces a small utility that generates deterministic UUIDs from a numeric model ID plus the model name, while allowing the original numeric ID to be recovered on the server side.
What is the idea
The intent of this PR is to solve the public UUIDs requirement with no changes neither, on DB or in the models. We can calculate fixed UUIDs and manage them in execution time. By the generation of deterministic UUIDs as output from a function, being capable of revert their state and to recover the original, the application is able to add a calculated attribute called "public_id" that differs substantially from the DB numeric ID. Furthermore, it generates the possibility of - by reverting the UUID to its original form - communicate the external inputs with the internal DB.
Rationale
For this project we need UUIDs that:
(numeric_id, model_name)pair.By encrypting a single 16‑byte block with AES and treating the ciphertext as a UUID, we get a reversible mapping controlled by a secret key that lives in configuration rather than in the database schema.
Notes
UUID_AES_KEYwill change the mapping for all existing UUIDs, so deployments should treat this key similarly toSECRET_KEYand keep it stable.A simple demostration
Checklist
djLint-er on any new code
changes
What type of PR is this?
Added/updated tests?
Related PRs, Issues etc