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

[FR] Algorithm for unique ID generation #2698

Open
Thaina opened this issue Sep 10, 2024 · 2 comments
Open

[FR] Algorithm for unique ID generation #2698

Thaina opened this issue Sep 10, 2024 · 2 comments

Comments

@Thaina
Copy link

Thaina commented Sep 10, 2024

Is your feature request related to a problem? Please describe.
When there is a time we rely on firebase to generate unique ID for firestore or authentication, sometimes we don't want complete random ID. There should be some option to control the ID generation algorithm

I wish I could generate ID that can be always sorted. At least incremental or any monotonic function should be allow to prepend to the generated ID, such as base64 encoded unix timestamp

Additionally it should allow specifying the length of id, and the allowed encode character such as, is it case-sensitive, only numeric or alphanumeric, is it allow symbol, so on. So we have

Describe the solution you'd like
For authentication, maybe it could have option at the firebase console to specify the detailed algorithm as checkbox/radio

For firestore. Actually I wish I could have ability to do servervalue string formatting. So I could have firestore server generate any field, include ID, with the string I want

For this particular case I think we should have

db.collection("users").add({ // Should allow push new document with __name__ as id
    "__name__": ServerValue.calculate("string(request.time.toMillis(),16).reverse() + hashing.crc32(request.path).toHexString()"), // use firebase rule syntax for server generate value
    data : "anydata"
});

The above example generate reverse hex string from time and hash of the path. This function guaranteed incremental from server timestamp but also seemingly random at start and the end

(Also I want to request that string() function in firebase rule system should have base argument for int value, and also reverse function)

Describe alternatives you've considered

There is a request to allow set custom ID in beforeUserCreated as requested in firebase/firebase-tools#5675

Same go for firestore blocking function #2077

Additional context
Is it possible to have firebase server issue request in github too?

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@dconeybe
Copy link

dconeybe commented Sep 10, 2024

@Thaina Thank you for the feature request. It is indeed an interesting idea. Unfortunately, this isn't something we can devote time to at the moment, but I'll keep this issue opened as a reminder. The best you can do at the moment is to generate the IDs client-side.

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

No branches or pull requests

4 participants