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

refactor: id prefixes #1546

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions openmeter/ent/db/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions openmeter/ent/schema/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type BillingProfile struct {

func (BillingProfile) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixBillingProfile)),
entutils.NamespaceMixin{},
entutils.TimeMixin{},
}
Expand Down Expand Up @@ -138,7 +138,7 @@ type BillingWorkflowConfig struct {

func (BillingWorkflowConfig) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixWorkflowConfig)),
entutils.NamespaceMixin{},
entutils.TimeMixin{},
}
Expand Down Expand Up @@ -190,7 +190,7 @@ type BillingInvoiceItem struct {

func (BillingInvoiceItem) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixBillingInvoiceItem)),
entutils.NamespaceMixin{},
entutils.TimeMixin{},
entutils.MetadataAnnotationsMixin{},
Expand Down Expand Up @@ -263,7 +263,7 @@ type BillingInvoice struct {

func (BillingInvoice) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixBillingInvoice)),
entutils.NamespaceMixin{},
entutils.TimeMixin{},
entutils.MetadataAnnotationsMixin{},
Expand Down
2 changes: 1 addition & 1 deletion openmeter/ent/schema/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Customer struct {

func (Customer) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.ResourceMixin{},
entutils.Must(entutils.ResourceMixin(IDPrefixCustomer)),
entutils.CustomerAddressMixin{
FieldPrefix: "billing",
},
Expand Down
2 changes: 1 addition & 1 deletion openmeter/ent/schema/entitlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Entitlement struct {

func (Entitlement) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixEntitlement)),
entutils.NamespaceMixin{},
entutils.MetadataAnnotationsMixin{},
entutils.TimeMixin{},
Expand Down
2 changes: 1 addition & 1 deletion openmeter/ent/schema/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Feature struct {

func (Feature) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixFeature)),
entutils.TimeMixin{},
entutils.MetadataAnnotationsMixin{},
}
Expand Down
2 changes: 1 addition & 1 deletion openmeter/ent/schema/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Grant struct {

func (Grant) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixGrant)),
entutils.NamespaceMixin{},
entutils.MetadataAnnotationsMixin{},
entutils.TimeMixin{},
Expand Down
34 changes: 34 additions & 0 deletions openmeter/ent/schema/idprefix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package schema

// 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)
Comment on lines +3 to +7
Copy link
Contributor

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?

Copy link
Contributor Author

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.


const (
// Billing
IDPrefixBillingProfile = "bi_p_"
IDPrefixBillingInvoice = "bi_i_"
IDPrefixBillingInvoiceItem = "bi_ii_"
IDPrefixWorkflowConfig = "bi_wc_"

// Customer
IDPrefixCustomer = "cus_"

// Entitlements
IDPrefixEntitlement = "en_"
IDPrefixEntitlementUsageReset = "en_ur_"

// Credits
IDPrefixGrant = "cr_g_"

// Notifications
IDPrefixNotificationChannel = "no_c_"
IDPrefixNotificationRule = "no_r_"
IDPrefixNotificationEvent = "no_e_"
IDPrefixNotificationEventDeliveryStatus = "no_ed_"

// Product catalog
IDPrefixFeature = "pr_f_"
)
8 changes: 4 additions & 4 deletions openmeter/ent/schema/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type NotificationChannel struct {

func (NotificationChannel) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixNotificationChannel)),
entutils.NamespaceMixin{},
entutils.TimeMixin{},
}
Expand Down Expand Up @@ -68,7 +68,7 @@ type NotificationRule struct {

func (NotificationRule) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixNotificationRule)),
entutils.NamespaceMixin{},
entutils.TimeMixin{},
}
Expand Down Expand Up @@ -117,7 +117,7 @@ type NotificationEvent struct {

func (NotificationEvent) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixNotificationEvent)),
entutils.NamespaceMixin{},
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ type NotificationEventDeliveryStatus struct {

func (NotificationEventDeliveryStatus) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixNotificationEventDeliveryStatus)),
entutils.NamespaceMixin{},
}
}
Expand Down
2 changes: 1 addition & 1 deletion openmeter/ent/schema/usage_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type UsageReset struct {

func (UsageReset) Mixin() []ent.Mixin {
return []ent.Mixin{
entutils.IDMixin{},
entutils.Must(entutils.IDMixin(IDPrefixEntitlementUsageReset)),
entutils.NamespaceMixin{},
entutils.TimeMixin{},
}
Expand Down
Loading
Loading