-
Notifications
You must be signed in to change notification settings - Fork 68
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
refactor: id prefixes #1546
base: main
Are you sure you want to change the base?
refactor: id prefixes #1546
Conversation
This change makes sure that going forward all IDs generated will have ID prefixes, causing easier identification of the entity in question. The old data is not modified.
@@ -169,3 +196,11 @@ func (c CustomerAddressMixin) Fields() []ent.Field { | |||
field.String(fmt.Sprintf("%s_address_phone_number", c.FieldPrefix)).Optional().Nillable(), | |||
} | |||
} | |||
|
|||
func Must(m ent.Mixin, err error) ent.Mixin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're already using it then i suggest maybe lo.Must
// Table of ID prefixes for each entity type. | ||
// Please make sure you are picking a unique prefix for each entity type. | ||
// Recommendation: | ||
// - at least 3 characters of the entity type name. | ||
// - max length is 8 characters (field size limit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is the hard part to get right. I'm not 100% scoping is the way to go, I'd rather define what to do in case of name collisions and use as short names as possible... wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, scoping is 100% TBD. Initially I was doing stuff like
- BillingInvoiveItem => bii_
- Customer => c_
But then I didn't like the one-character names, so that's why I ended up with this scoping thing. I am not against dropping that part.
I would just mandate that there are no collisions, as seven characters should be enough.
} | ||
|
||
func (i idMixin) ULIDWithPrefix() string { | ||
return fmt.Sprintf("%s_%s", i.IDPrefix, ulid.Make().String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: With the current IDs the _ is a duplicate.
-- modify "billing_invoice_items" table | ||
ALTER TABLE "billing_invoice_items" ALTER COLUMN "id" TYPE character varying(34), ALTER COLUMN "invoice_id" TYPE character varying(34); | ||
-- modify "billing_invoices" table | ||
ALTER TABLE "billing_invoices" ALTER COLUMN "id" TYPE character varying(34), ALTER COLUMN "billing_profile_id" TYPE character varying(34), ALTER COLUMN "workflow_config_id" TYPE character varying(34); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: we need to change the schema override too (or remove in case of edge fields as it seems like ent autogenerates the types)
@turip I believe we agreed we'd postpone the id prefixing for the time being, and once we do it would only affect new IDs. Would you be fine with closing this PR, or is this still relevant? |
Overview
This change makes sure that going forward all IDs generated will have ID prefixes, causing easier identification of the entity in question.
The old data is not modified.
Notes for reviewer