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

idea: Add new prefixes and resource IDs #530

Open
TreyWW opened this issue Nov 15, 2024 · 2 comments
Open

idea: Add new prefixes and resource IDs #530

TreyWW opened this issue Nov 15, 2024 · 2 comments

Comments

@TreyWW
Copy link
Owner

TreyWW commented Nov 15, 2024

Companies like Stripe and AWS use prefixed resource IDs to allow users and developers to much more easily identify resources.

For example, our current system has ids like 1235, whereas stripe has inv_3LKQhvGUcADgqkAd5bd6pslE or AWS has like i-12dNk2354asdhsa.

The prefixes inv-, i-, cl_ etc all help with identifying the object type without needing to know extra details, useful for debugging and being human readable for users.

I think it'd be ideal for us to move to this design too, but it'll need a bit of rethinking and model changes.

We'd need a random character based string for IDs rather than integers, like UUIDs, so they can't be guessed - this is generally good in general for any public facing things anyways. And then we'd append the prefix via a model manager or something of the kind.

Seems like a waste of storage (even though only a few bytes) to append the prefix in DB, so I feel like it should be done on the backend.

All items should still have their NORMAL autoincrement ID, but this will never be publicly facing. I believe this is ideal to still have as it is good for efficiency in DB lookups and indexing - correct me if i'm wrong though.

@TreyWW TreyWW added idea idea: suggested This idea has been suggested. Awaiting recognition. good first issue Good for newcomers discussion help-wanted priority: high group issue idea: deciding This idea is being decided + validated and removed idea: suggested This idea has been suggested. Awaiting recognition. labels Nov 15, 2024
@TreyWW TreyWW pinned this issue Nov 15, 2024
@TreyWW
Copy link
Owner Author

TreyWW commented Nov 15, 2024

A possible django solutionwould be something like:

resource_id_raw = UUID()

@property
def resource_id(self)
    return f'prefix_{self.resource_id_raw}'

Then you just use invoice.resource_id or x.resource_id and that becomes a globally used thing instead of number IDs.

We could have shorter aliases such as rid too, as long as it's not confusing.

Any thoughts?

@lamia-alam
Copy link

Hi! My name is Lamia and I’ve never contributed to an open source project before, but I’d like to try working on this issue! Is it still available?

@TreyWW TreyWW unpinned this issue Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants