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

Merged
merged 1 commit into from
Dec 5, 2024
Merged

Subscription Internals V2 #1851

merged 1 commit into from
Dec 5, 2024

Conversation

GAlexIHU
Copy link
Contributor

@GAlexIHU GAlexIHU commented Nov 14, 2024

Overview

Supersedes #1732

Includes internal APIs for subscription Management

  1. DB Entities
  • Subscription
  • SubscriptionPhase
  • SubscriptionItem
  • SubscriptionEntitlement
  1. Interfaces
  • Subscription Service (mostly package internal API) with
    • Create
    • Get
    • Expand
    • Edit
    • Cancel
    • Continue (a canceled)
  • Workflow Service (external API), with
    • CreateFromPlan
    • EditRunning (via patches)
  • "Patch" Commands for (name TBD) to be used with Create & Edit
    • AddItem
    • RemoveItem
    • AddPhase
    • RemovePhase
    • StretchPhase
  • SubscriptionXSpec & SubscriptionXView interfaces
    • define create specifications and defacto state for Subscriptions & its subresources
  1. Misc
  • Testutils for Subscriptions
  • ULID feature keys are no longer supported

Notes for reviewer

  • None of openmeter/subscriptions is included in application startup.

@GAlexIHU GAlexIHU added the kind/feature New feature or request label Nov 14, 2024
@GAlexIHU GAlexIHU force-pushed the feat/subscriptions2 branch 2 times, most recently from 1df72dc to 0e7a9ea Compare November 19, 2024 12:12
@GAlexIHU GAlexIHU force-pushed the feat/subscriptions2 branch from 4b22a4e to fdcda89 Compare November 26, 2024 17:03
@GAlexIHU GAlexIHU marked this pull request as ready for review November 26, 2024 17:07
@GAlexIHU GAlexIHU force-pushed the feat/subscriptions2 branch from 1267792 to 6575f86 Compare November 27, 2024 12:03
@GAlexIHU GAlexIHU added release-note/misc Miscellaneous changes release-note/feature Release note: Exciting New Features and removed release-note/misc Miscellaneous changes labels Nov 27, 2024
field.String("key").NotEmpty().Immutable(),
field.String("name").NotEmpty(),
field.String("description").Optional().Nillable(),
field.Time("active_from").Immutable(),
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we need an optional active_to? Or that coming from rate cards somehow? If yes why do we need active_from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the current spec, a subscription cannot have a state where there isn't an active phase, unless the subscription itself is inactive (cancelled etc...) it's just a simple way of guaranteeing it

return []ent.Edge{
edge.From("subscription", Subscription.Type).Field("subscription_id").Ref("phases").Unique().Immutable().Required(),
edge.To("items", SubscriptionItem.Type),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add a unqiue index for subscription_id + phase key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can add a unique index for subscription_id + phase_key + deletedAt (taking into account that deletedAt is nillable)

func (SubscriptionItem) Edges() []ent.Edge {
return []ent.Edge{
edge.From("phase", SubscriptionPhase.Type).Field("phase_id").Ref("items").Unique().Immutable().Required(),
edge.To("entitlements", SubscriptionEntitlement.Type),
Copy link
Contributor

Choose a reason for hiding this comment

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

should we define db field to be entitlement_id?

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, now that SubscriptionItem is materialized we can do away with the linking table

GoType(datex.ISOString("")).Nillable().Optional(),
field.String("key").NotEmpty().Immutable(),
field.String("rate_card").
GoType(&subscription.RateCard{}).
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason it's not materialized? In product catalog rate card is materialized:
https://github.com/openmeterio/openmeter/blob/main/openmeter/ent/schema/productcatalog.go#L119

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now mainly for simplicity and time saving. ProductCatalog models (like RateCard) should be made available for use outside of those packages which is currently not possible, the subscription.RateCard should disappear once that is resolved. I'd be much happier to reuse the exact code used in Plan for much of this, but you're right that's not a requirement, I'm happy to normalize it if you'd like, it's just a bit of double work, but there's already quite a bit of double work happening so that doesn't have to be an issue.

@GAlexIHU GAlexIHU force-pushed the feat/subscriptions2 branch from 6575f86 to 212a44a Compare December 2, 2024 10:42
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

refactor(test): rewrite tests to use ent schema upserts

feat(subscription): guard managed entitlements

feat(subscription): write first version of workflow service

fix(subs): rebase errors

feat(subs): add statemation to control transitions

feat(subs): cancelation and continuing

refactor(subs): calculate item cadence from itemSpec

refactor(subs): remove CadencedModel from SubscriptionItem and make its cadence relative to phase

feat(subs): implement correct editing of current phase

refactor(subs): use custom RateCard type

feat(subs): add validations for Spec and View

feat(subs): add back CadencedModel to SubscriptionItem

chore: generate migrations

fix(e2e): fix e2e tests to use non-ulid featureKey

refactor(subs): normalize RateCard

refactor(subs): regenerate migrations

docs(*): rename and document item relative cadence

refactor(subs): remove subscription_entitlement table
@GAlexIHU GAlexIHU force-pushed the feat/subscriptions2 branch from 212a44a to 4085c33 Compare December 4, 2024 16:23
@GAlexIHU GAlexIHU merged commit 01f1ad1 into main Dec 5, 2024
24 checks passed
@GAlexIHU GAlexIHU deleted the feat/subscriptions2 branch December 5, 2024 11:01
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 release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants