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

Subscription Internals V2 #1851

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Subscription Internals V2 #1851

wants to merge 9 commits into from

Conversation

GAlexIHU
Copy link
Contributor

Overview

Supersedes #1732

Includes internal service for subscription management.

Notes for reviewer

  • PR is pending until Plan types have been extracted to models. They affect a significant portion of the types, and migrations cannot be generated without them present.
  • None of openmeter/subscriptions is included in application startup.

@GAlexIHU GAlexIHU added the kind/feature New feature or request label Nov 14, 2024
openmeter/ent/schema/price.go Outdated Show resolved Hide resolved
func (SubscriptionItem) Fields() []ent.Field {
return []ent.Field{
field.String("phase_id").NotEmpty().Immutable(),
field.String("key").NotEmpty().Immutable(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a key for it, isn't ID enaough? Do we expect users to name subscription items manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid linking I'll copy from relevant docs

SubscriptionItem can be identified, it has a reference:

  • If a Feature is associated with the SubscriptionItem, it is identified by the Feature
    • It can be an ID reference, for an exact version of the Feature (Features can change across versions)
    • It can be a Key reference, which always refers to the latest (active or inactive) version of a Feature
  • If a Feature is not associated with the SubscriptionItem, it is referenced by the Price
    • We say “referenced by the Price” regardless of how a price itself is referenced, it colloquially makes sense to say “paying the same price for the same thing”
      In practice this will need an ID (key) being generated

Keys are used for identifying the "same thing" across different instances (with different IDs)

openmeter/ent/schema/subscription_entitlement.go Outdated Show resolved Hide resolved
openmeter/ent/schema/subscription_entitlement.go Outdated Show resolved Hide resolved
field.String("phase_id").NotEmpty().Immutable(),
field.String("key").NotEmpty().Immutable(),
// TODO: pending PR
field.String("rate_card").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this a reference to plan_rate_card table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a direct reference to an actual plan's actual ratecard, it will only hold the same contents as a ratecard does.

entutils.IDMixin{},
entutils.NamespaceMixin{},
entutils.TimeMixin{},
entutils.MetadataAnnotationsMixin{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need annotations instead of just adding a readonly or editable flag like: field.Bool("readonly").NotEmpty().Immutable().Default(false) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the question.

// pkg/models/model.go
type AnnotatedModel struct {
	Metadata map[string]string `json:"metadata,omitempty"`
}
// pkg/framework/entutils/mixin.go
// MetadataAnnotationsMixin adds metadata to the schema
type MetadataAnnotationsMixin struct {
	mixin.Schema
}

// Fields of the IDMixin.
func (MetadataAnnotationsMixin) Fields() []ent.Field {
	return []ent.Field{
		field.JSON("metadata", map[string]string{}).
			Optional().
			SchemaType(map[string]string{
				dialect.Postgres: "jsonb",
			}),
	}
}

openmeter/entitlement/scheduling.go Outdated Show resolved Hide resolved
openmeter/subscription/adapters/entitlement/adapter.go Outdated Show resolved Hide resolved
feat: subscription creation wireframing

refactor: move subscriptions out of productcatalog

refactor: fresh start

feat(subs): define interfaces and subpackages

feat(subs): write individual patches

feat: implement patch serialization

feat: db structure for patches

fix(subs): date use in patches

fix: date use in subscription patches

chore: uncomment methods

fix: fix rebase issues

feat(subs): subscription creation and patch saving

feat: add entitlement annotations

feat: write patch saving

feat: subscriptionView

feat: write db schema for patches

feat(subs): write entity mappings for repository

feat(subs): implement and test create and read

feat: implement price

test: write command and query builders

test: subscription creation without customizations

test(subs): test creation with customizations

refactor(sub): marry command and query

feat(subs): write syncing

test: test entity syncing

feat: test editing and fix rebase errors

chore: generate migrations

chore: remove dangling execs

fix: use patch timestamp instead of operation timestamp for validations

chore: remove dead code

fix(lint): fix lint errors

feat: incorporate new price types

chore: undo me

test(subs): service create and view tests

feat(subs): define workflow service

fix(subs): consolidate key and id use when linking things
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants