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 IsCustom #2414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Subscription IsCustom #2414

wants to merge 1 commit into from

Conversation

GAlexIHU
Copy link
Contributor

@GAlexIHU GAlexIHU commented Mar 11, 2025

Overview

  • Storing the timestamp of the last edit on the subscription
  • Adding IsCustom field: if a subscription doesn't have a plan ref (created as a custom sub) or is edited (has edit timestamp) it will be a custom subscription.
  • We don't try to guess last edit times for existing subscriptions: for existing subs, they'll only be custom if they dont have a planref

Summary by CodeRabbit

  • New Features
    • Subscriptions now show a custom indicator when they are manually modified.
    • A "last edited" timestamp is provided to help track when subscriptions were updated.
  • Bug Fixes
    • Subscription updates now enforce proper customization; attempts without customizations display a clear error message.

@GAlexIHU GAlexIHU added the release-note/feature Release note: Exciting New Features label Mar 11, 2025
@GAlexIHU GAlexIHU requested a review from solkimicreb March 11, 2025 13:27
@GAlexIHU GAlexIHU self-assigned this Mar 11, 2025
@GAlexIHU GAlexIHU requested a review from a team as a code owner March 11, 2025 13:27
Copy link

coderabbitai bot commented Mar 11, 2025

📝 Walkthrough

Walkthrough

A comprehensive update adds a new isCustom flag to subscription models across API schemas, client libraries, and internal service layers to indicate custom subscriptions. In parallel, a last_edited_at timestamp field has been introduced across the database schema, entity mutations, repository methods, and mapping functions to track when a subscription was edited. Corresponding methods, predicates, and SQL migrations have been added, and validation for customizations in the workflow service (with updated tests) has been enhanced.

Changes

File(s) Change Summary
api/api.gen.go, api/client/go/client.gen.go, api/client/javascript/src/client/schemas.ts, api/openapi{.yaml,.cloud.yaml}, api/spec/src/.../subscription.tsp Added new boolean field/property isCustom to the Subscription and SubscriptionExpanded models. Also updated swaggerSpec string content.
openmeter/ent/db/... (e.g. migrate/schema.go, mutation.go, setorclear.go, subscription.go, subscription_create.go, subscription_update.go, subscription/where.go)
openmeter/ent/schema/subscription.go
Introduced new timestamp field last_edited_at along with methods, predicates, and migration adjustments to support tracking subscription edits.
openmeter/productcatalog/subscription/http/mapping.go,
openmeter/subscription/repo/... (e.g. mapping.go, subscriptionrepo.go),
openmeter/subscription/{repository.go, service/service.go, subscription.go}
Updated repository, mapping, and service functions to handle the new last_edited_at field and incorporate IsCustom logic.
openmeter/subscription/service/{workflowservice.go, workflowservice_test.go} Added a validation step in EditRunning to error when no customizations are provided and updated test cases accordingly.
tools/migrate/migrations/20250311123806_subscription-editedat.{up,down}.sql Added SQL migrations to add (up) and drop (down) the last_edited_at column in the subscriptions table.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@GAlexIHU GAlexIHU force-pushed the galexi/subs-edited-status branch from a6d0ca1 to c95aa7e Compare March 11, 2025 13:31
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
openmeter/subscription/subscription.go (1)

32-46: 💡 Verification agent

🧩 Analysis chain

The AsEntityInput method doesn't propagate the new LastEditedAt field.

The AsEntityInput() method doesn't include the newly added LastEditedAt field when creating a CreateSubscriptionEntityInput. This might lead to the edit timestamp being lost when converting between representations.


🏁 Script executed:

#!/bin/bash
# Check if CreateSubscriptionEntityInput has a LastEditedAt field
# and how this field is used in other parts of the codebase

echo "Checking if CreateSubscriptionEntityInput struct has LastEditedAt field:"
rg "type CreateSubscriptionEntityInput struct" -A 20

echo -e "\nChecking where AsEntityInput is used:"
rg "AsEntityInput\(\)" -B 2 -A 2

Length of output: 2667


Action Required: Propagate the New LastEditedAt Field in the Entity Conversion

The current implementation of the AsEntityInput method in openmeter/subscription/subscription.go does not include the new LastEditedAt field. This omission means that when converting a Subscription into a CreateSubscriptionEntityInput, any updated timestamp indicating the last edit is not propagated, potentially resulting in stale edit metadata. To resolve this, please:

  • Update the CreateSubscriptionEntityInput struct (located in openmeter/subscription/repository.go) to include a LastEditedAt field if it’s meant to track edit timestamps.
  • Modify the AsEntityInput method to assign s.LastEditedAt to the corresponding field of the input struct.
  • Verify the changes wherever AsEntityInput is used (e.g., in openmeter/subscription/service/service.go) to ensure that the edit timestamp is correctly passed through the conversion.
🧹 Nitpick comments (10)
api/openapi.yaml (2)

15830-15841: Clear documentation for the isCustom property.
The added schema for isCustom is well documented, explaining that a subscription is custom if it either lacks a plan reference or has been edited. One minor nitpick: the description uses "it's original form" where the correct possessive is "its original form." Consider fixing this for grammatical accuracy.


16005-16016: Replication of the isCustom field in the expanded schema.
The changes correctly integrate the isCustom field into this part of the schema, mirroring the previous definition. The description is clear; however, as noted earlier, please update "it's original form" to "its original form" for grammatical correctness.

tools/migrate/migrations/20250311123806_subscription-editedat.down.sql (1)

1-2: SQL Down Migration: Revert last_edited_at Column Addition

The migration correctly drops the last_edited_at column from the "subscriptions" table as part of the rollback process. Consider verifying that there are no dependent queries or application logic that might break when the column is removed. Optionally, you might add an IF EXISTS clause to avoid errors if the column does not exist in some environments.

api/client/javascript/src/client/schemas.ts (2)

7110-7113: Code looks good with a minor grammatical issue

The implementation of the isCustom field in the Subscription schema is well-documented and aligns with the PR objectives. The field correctly identifies custom subscriptions based on the specified criteria.

There is a small grammatical error in the documentation:

-      /** @description Whether the subscription is custom. A subscription is custom if
-       *     - it was customized at creation (not based on a plan, has no PlanReference)
-       *     - or if it has been edited (even if eventually edited back to it's original form) */
+      /** @description Whether the subscription is custom. A subscription is custom if
+       *     - it was customized at creation (not based on a plan, has no PlanReference)
+       *     - or if it has been edited (even if eventually edited back to its original form) */

7232-7235: Same grammatical issue in SubscriptionExpanded schema

The implementation for the SubscriptionExpanded schema looks good but contains the same grammatical error.

-      /** @description Whether the subscription is custom. A subscription is custom if
-       *     - it was customized at creation (not based on a plan, has no PlanReference)
-       *     - or if it has been edited (even if eventually edited back to it's original form) */
+      /** @description Whether the subscription is custom. A subscription is custom if
+       *     - it was customized at creation (not based on a plan, has no PlanReference)
+       *     - or if it has been edited (even if eventually edited back to its original form) */
tools/migrate/migrations/20250311123806_subscription-editedat.up.sql (1)

1-3: New SQL Migration: Adding "last_edited_at" Column

The migration script correctly adds the new nullable "last_edited_at" column of type timestamptz to the "subscriptions" table. This aligns with the PR objectives to store the last edit timestamp, which will serve as an indicator for custom subscriptions.

Suggestions:

  • Index Consideration: If the last_edited_at column is expected to be frequently queried (e.g., sorting or filtering by edit timestamps), consider adding an index on this column in a future migration.
  • Default Value: Confirm that having this column nullable (with no default value) fits the requirements for both new and existing subscriptions.
api/openapi.cloud.yaml (2)

15550-15561: Property Definition for isCustom

The new isCustom property is clearly defined with type boolean and a detailed description explaining its criteria. One minor suggestion: consider correcting the possessive typo in the description—change "it's original form" to "its original form" to improve clarity.


15725-15736: Schema Extension with isCustom for Subscription Mapping

The inclusion of the isCustom field in the schema—with its associated type and descriptive text—provides a clear and self-documenting mechanism for identifying custom subscriptions. Again, please consider updating the phrase "even if eventually edited back to it's original form" to "its original form" for grammatical correctness.

api/api.gen.go (2)

4654-4657: Documentation comment has a minor typo

The documentation for the IsCustom field has a small grammatical error in the third bullet point. It should be "its" (possessive) rather than "it's" (contraction for "it is").

 // IsCustom Whether the subscription is custom. A subscription is custom if
 // - it was customized at creation (not based on a plan, has no PlanReference)
-// - or if it has been edited (even if eventually edited back to it's original form)
+// - or if it has been edited (even if eventually edited back to its original form)
 IsCustom bool `json:"isCustom"`

4749-4752: Same typo in the second documentation block

This documentation comment has the same grammatical error as the previous one.

 // IsCustom Whether the subscription is custom. A subscription is custom if
 // - it was customized at creation (not based on a plan, has no PlanReference)
-// - or if it has been edited (even if eventually edited back to it's original form)
+// - or if it has been edited (even if eventually edited back to its original form)
 IsCustom bool `json:"isCustom"`
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c425d7b and c95aa7e.

⛔ Files ignored due to path filters (1)
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum
📒 Files selected for processing (25)
  • api/api.gen.go (5 hunks)
  • api/client/go/client.gen.go (3 hunks)
  • api/client/javascript/src/client/schemas.ts (2 hunks)
  • api/openapi.cloud.yaml (4 hunks)
  • api/openapi.yaml (4 hunks)
  • api/spec/src/productcatalog/subscription.tsp (1 hunks)
  • openmeter/ent/db/migrate/schema.go (3 hunks)
  • openmeter/ent/db/mutation.go (10 hunks)
  • openmeter/ent/db/setorclear.go (1 hunks)
  • openmeter/ent/db/subscription.go (4 hunks)
  • openmeter/ent/db/subscription/subscription.go (3 hunks)
  • openmeter/ent/db/subscription/where.go (2 hunks)
  • openmeter/ent/db/subscription_create.go (5 hunks)
  • openmeter/ent/db/subscription_update.go (4 hunks)
  • openmeter/ent/schema/subscription.go (1 hunks)
  • openmeter/productcatalog/subscription/http/mapping.go (2 hunks)
  • openmeter/subscription/repo/mapping.go (1 hunks)
  • openmeter/subscription/repo/subscriptionrepo.go (1 hunks)
  • openmeter/subscription/repository.go (1 hunks)
  • openmeter/subscription/service/service.go (1 hunks)
  • openmeter/subscription/service/workflowservice.go (1 hunks)
  • openmeter/subscription/service/workflowservice_test.go (1 hunks)
  • openmeter/subscription/subscription.go (2 hunks)
  • tools/migrate/migrations/20250311123806_subscription-editedat.down.sql (1 hunks)
  • tools/migrate/migrations/20250311123806_subscription-editedat.up.sql (1 hunks)
🔇 Additional comments (56)
api/openapi.yaml (2)

15753-15759: Insertion of the new isCustom field in field listings.
The new field isCustom is correctly added in the field list alongside existing fields such as activeFrom, status, and customerId. This ensures that clients are aware of the field as part of the model.


15931-15937: Consistent inclusion of isCustom in the properties list.
The update in this section consistently includes the isCustom field in the list of properties along with activeFrom, status, customerId, currency, and phases. This maintains uniformity across the model definitions.

api/openapi.cloud.yaml (2)

15473-15479: New Required Field Addition: isCustom in Object List

The addition of the - isCustom element to the list ensures that this new field is explicitly required in the object. This aligns with the subscription logic whereby a subscription is considered custom if it either lacks a plan reference or has been edited. Verify that this change is consistent with your overall API design and that downstream consumers are aware of the new required property.


15651-15657: Consistent Inclusion of isCustom in Required Lists

This hunk introduces - isCustom consistently within another related object’s required list. Ensure that marking isCustom as required for both objects is intentional and that any necessary documentation or client library adjustments are made to reflect this requirement.

openmeter/ent/schema/subscription.go (1)

38-38: LGTM: Added last_edited_at field to track subscription edits

The new last_edited_at field is well-defined with appropriate modifiers:

  • Optional() allows the field to be omitted
  • Nillable() allows the field to be explicitly set to NULL

This implementation aligns with the PR objective of tracking when a subscription was last edited.

api/spec/src/productcatalog/subscription.tsp (1)

99-104: LGTM: Well-documented isCustom property

The new isCustom boolean property is added with comprehensive documentation that clearly defines when a subscription is considered custom:

  1. When created without a plan reference
  2. When it has been edited at any point

This implementation matches the PR objectives and provides clear guidance for API consumers.

openmeter/subscription/service/workflowservice.go (1)

89-91: Good addition: Empty customizations validation

This validation check prevents processing empty customization lists, failing early with a clear error message. This is a good defensive programming practice that improves error handling in the workflow service.

openmeter/subscription/repository.go (1)

51-52: LGTM: New MarkEdited method for tracking subscription customizations

The new MarkEdited method provides a clean interface for marking subscriptions as custom when they're edited. This method:

  • Takes a timestamp parameter to record when the edit occurred
  • Returns the updated subscription
  • Has a clear, concise description

This implementation supports the PR objective of tracking subscription edits.

openmeter/ent/db/subscription.go (5)

50-51: Well-structured field addition for tracking subscription edits.

The LastEditedAt field addition is properly documented and follows the same pattern as other nullable time fields in the struct. This aligns with the PR objective to store the timestamp of the last edit made to a subscription.


124-125: Correctly updated scan values method to handle the new field.

The scanValues method is appropriately updated to include the new LastEditedAt field, ensuring it's handled as a sql.NullTime type during database operations.


231-237: Properly implemented value assignment for LastEditedAt.

The assignment logic is consistent with other nullable time field implementations, correctly handling type checking, validity verification, and value assignment.


340-344: String method correctly updated to include LastEditedAt.

The String method is properly updated to include the new field in the string representation, with appropriate null checking and time formatting.


19-56:

❌ Incorrect review comment

Missing IsCustom method in the Subscription struct.

The PR objectives specify that an IsCustom field/method should be added to determine whether a subscription is custom based on either lacking a plan reference or having an edit timestamp. This functionality appears to be missing from the implementation.

Please verify this with the following script:


🏁 Script executed:

#!/bin/bash
# Check if IsCustom method exists in other files in the codebase
rg -A 5 "func \(\w+ (Subscription|subscription)\) IsCustom\(\)" --type go

Length of output: 284


Clarification: The IsCustom method is not missing.
The necessary IsCustom functionality is implemented in the repository within the file openmeter/subscription/subscription.go:

  • The method signature is:
    func (s Subscription) IsCustom() bool {
        return s.LastEditedAt != nil || s.PlanRef == nil
    }
  • This implementation meets the PR objectives to determine if a subscription is custom (i.e., lacking a plan reference or having a non-nil edit timestamp).

Please update the documentation or references if needed to point to this implementation.

Likely an incorrect or invalid review comment.

openmeter/ent/db/subscription/subscription.go (3)

43-44: Appropriate field constant declaration.

The constant for the new field follows the existing naming pattern and clearly documents its purpose.


101-101: Correctly added LastEditedAt to Columns slice.

The field is properly added to the Columns slice, ensuring it's included in database operations.


205-208: Well-implemented ordering function for LastEditedAt.

The ByLastEditedAt function follows the same pattern as other ordering functions, allowing proper ordering by the new field in queries.

openmeter/subscription/repo/mapping.go (1)

48-53: Correctly mapped LastEditedAt in the domain model.

The field mapping is properly implemented, ensuring that the LastEditedAt timestamp is converted to UTC and included in the mapped subscription object. This maintains consistency with other time fields in the mapping function.

openmeter/subscription/service/service.go (1)

203-207: Properly implemented edit timestamp tracking.

The edit timestamp is now correctly updated during subscription modifications by calling the MarkEdited method with the current time. This implementation aligns with the PR objective to track the last edit time for subscriptions.

openmeter/subscription/repo/subscriptionrepo.go (1)

32-47: Looks good - Implementation follows proper repository pattern

The implementation of MarkEdited follows the established repository pattern in the codebase, properly using transactions, error handling, and UTC time conversion. This aligns with the PR's objective to track modifications to subscriptions by storing the edit timestamp.

openmeter/ent/db/setorclear.go (1)

2088-2100: Implementation correctly follows the established pattern

The new SetOrClearLastEditedAt methods for both SubscriptionUpdate and SubscriptionUpdateOne types follow the consistent pattern seen throughout the file. They handle the nullable LastEditedAt field appropriately, ensuring it can be either set or cleared based on whether a value is provided.

api/api.gen.go (3)

13964-14008: Auto-generated Swagger spec changes look good

These changes to the embedded Swagger specification correctly reflect the addition of the IsCustom field to the API models. This is auto-generated content that properly documents the API changes.


14022-14025: Auto-generated Swagger spec changes (continued)

Continuing the auto-generated changes to the Swagger specification. No issues found.


14040-14364: Remaining auto-generated Swagger spec changes look good

The rest of the changes to the embedded Swagger specification continue to document the API changes. This is expected for auto-generated content.

openmeter/subscription/subscription.go (2)

27-29: Well-structured field addition for tracking subscription edits.

The LastEditedAt field is properly implemented as a pointer to time.Time with an appropriate JSON tag that includes omitempty. This aligns well with the PR objective of storing the timestamp of the last edit to a subscription.


73-75: Clear and concise implementation of the IsCustom logic.

The method correctly implements the custom subscription logic as defined in the PR objectives - a subscription is custom if it either lacks a plan reference or has been edited (indicated by LastEditedAt not being nil).

api/client/go/client.gen.go (3)

4553-4556: Implementation of IsCustom field looks good.

The new IsCustom boolean field has been properly added to the Subscription struct with clear documentation explaining when a subscription is considered custom. The field follows Go naming conventions and is correctly tagged for JSON serialization.


4648-4651: Implementation of IsCustom field is consistent.

The IsCustom field has been implemented consistently in the SubscriptionExpanded struct with identical documentation and JSON tagging, maintaining consistency across related structs.


30428-30742: Swagger spec updates align with model changes.

The swagger spec has been appropriately updated to include the new isCustom field. These changes appear to be auto-generated and align with the model definition changes made above.

openmeter/productcatalog/subscription/http/mapping.go (2)

194-194: Implementation of the IsCustom flag.

The new IsCustom field is correctly added to the API subscription model, using the IsCustom() method from the subscription domain model. This fulfills the requirement to expose this information via the API.


523-523: Correctly propagates IsCustom to the expanded subscription view.

The IsCustom field is properly forwarded from the basic subscription API model to the expanded subscription API model, ensuring consistency across different API representations.

openmeter/subscription/service/workflowservice_test.go (1)

123-129: Updated test expectation to match new validation requirement.

The test case has been updated to expect an error when no patches are provided, rather than expecting no action to occur. This change correctly aligns with the new validation in the workflow service that requires at least one customization when editing a subscription.

This change in behavior makes sense for tracking custom subscriptions as described in the PR objectives - requiring explicit customizations helps identify which subscriptions have been edited.

openmeter/ent/db/subscription_update.go (4)

160-178: Added LastEditedAt field methods to SubscriptionUpdate.

These new methods properly implement the database operations for the last_edited_at field, which is essential for tracking when a subscription was last edited. This field is a key part of the PR's objectives to identify custom subscriptions.

The implementation follows the consistent pattern used for other time fields in this generated code.


362-367: Added LastEditedAt field handling in sqlSave method.

The sqlSave method is correctly updated to handle the new last_edited_at field, ensuring proper database persistence when updating subscriptions.


633-651: Added LastEditedAt field methods to SubscriptionUpdateOne.

These methods implement the necessary operations for the single-entity update variant, maintaining consistency with the batch update implementation.


865-870: Added LastEditedAt field handling in SubscriptionUpdateOne.sqlSave.

The single-entity sqlSave method is properly updated to handle the last_edited_at field, ensuring consistency with the batch update implementation.

openmeter/ent/db/migrate/schema.go (4)

1688-1688: Well-designed column addition for tracking subscription edits.

The addition of the last_edited_at column with nullable Time type is well-implemented and aligns perfectly with the PR objective of tracking when a subscription was last edited. This field will be essential for determining if a subscription is custom.


1700-1703: Properly updated foreign key reference for customer ID.

The column index has been correctly adjusted from 12 to 13 to account for the newly added last_edited_at field, maintaining proper foreign key relationships.


1705-1709: Properly updated foreign key reference for plan ID.

The column index has been correctly adjusted from 13 to 14 to account for the newly added last_edited_at field, maintaining proper foreign key relationships.


1728-1731: Properly updated index for namespace and customer ID.

The column index has been correctly adjusted to reference the new column positions after adding the last_edited_at field, ensuring database indexes remain valid.

openmeter/ent/db/mutation.go (10)

36869-36869: Field addition looks good.

The addition of last_edited_at field to the SubscriptionMutation struct aligns with the PR objective of tracking when a subscription was last edited.


37523-37570: Well-implemented field management methods.

The implementation includes all necessary methods for managing the last_edited_at field (set, get, get old value, clear, check if cleared, reset). The error handling in OldLastEditedAt correctly validates the operation type and ID presence before fetching the old value.


37768-37768: Capacity adjustment is correct.

Increasing the capacity of the fields slice from 13 to 14 accommodates the new last_edited_at field.


37808-37810: Field inclusion logic is properly implemented.

The code correctly appends the last_edited_at field to the fields list when it's set.


37845-37846: Field accessor method properly updated.

The Field method is correctly extended to return the value of the last_edited_at field.


37882-37883: OldField accessor method properly updated.

The OldField method is correctly extended to return the old value of the last_edited_at field.


37984-37990: SetField method properly updated.

The SetField method is correctly extended to handle setting the last_edited_at field with appropriate type checking.


38036-38038: ClearedFields method properly updated.

The method now correctly includes the last_edited_at field when it has been cleared.


38068-38070: ClearField method properly updated.

The ClearField method is correctly extended to handle clearing the last_edited_at field.


38118-38120: ResetField method properly updated.

The ResetField method is correctly extended to handle resetting the last_edited_at field.

openmeter/ent/db/subscription/where.go (2)

130-133: Methods for the new LastEditedAt field look well-implemented

This addition introduces the main equality predicate for the new last_edited_at field that will be used to track subscription edits, aligning with the PR objective of determining custom subscriptions.


804-852: Complete set of predicate functions for the last_edited_at field

These predicate functions follow the standard pattern used for other fields in the Subscription entity, providing a full range of comparison operators (EQ, NEQ, GT, LT, etc.) and nullability checks. The implementation is thorough and consistent with the codebase's patterns.

openmeter/ent/db/subscription_create.go (5)

173-185: Well-implemented creation methods for the new field

These methods correctly handle setting the last_edited_at field during subscription creation, with proper null-handling logic that follows the established pattern of the codebase.


427-430: Properly integrated into the creation spec

The last_edited_at field is correctly integrated into the createSpec method, ensuring that the value will be properly set in the database when a new subscription is created.


675-691: Proper upsert operations for the new field

These methods provide the necessary functionality for handling the last_edited_at field during upsert operations, allowing for setting, updating, and clearing the field value.


903-922: Single item upsert operations implemented correctly

These methods correctly implement the operations needed for the last_edited_at field in the context of upserting a single item, maintaining consistency with the codebase patterns.


1301-1320: Bulk upsert operations implemented correctly

These methods provide the necessary bulk upsert functionality for the last_edited_at field, completing the full set of CRUD operations required for the new field.

@@ -35,6 +35,7 @@ func (Subscription) Fields() []ent.Field {
field.String("plan_id").Optional().Nillable(),
field.String("customer_id").NotEmpty().Immutable(),
field.String("currency").GoType(currencyx.Code("")).MinLen(3).MaxLen(3).NotEmpty().Immutable(),
field.Time("last_edited_at").Optional().Nillable(),
Copy link
Contributor

@tothandras tothandras Mar 11, 2025

Choose a reason for hiding this comment

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

updated_at is not the same, simply edited_at? but I'm fine with last_edited_at

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, that's the resource's updated at. last_edited_at is for the whole subscription

@@ -29,6 +29,23 @@ func NewSubscriptionRepo(db *db.Client) *subscriptionRepo {
}
}

func (r *subscriptionRepo) MarkEdited(ctx context.Context, id models.NamespacedID, at time.Time) (subscription.Subscription, error) {
return entutils.TransactingRepo(ctx, r, func(ctx context.Context, repo *subscriptionRepo) (subscription.Subscription, error) {
ent, err := repo.db.Subscription.UpdateOneID(id.ID).SetLastEditedAt(at.UTC()).Where(dbsubscription.Namespace(id.Namespace)).Save(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

move where close to the beginning

Suggested change
ent, err := repo.db.Subscription.UpdateOneID(id.ID).SetLastEditedAt(at.UTC()).Where(dbsubscription.Namespace(id.Namespace)).Save(ctx)
ent, err := repo.db.Subscription.UpdateOneID(id.ID).Where(dbsubscription.Namespace(id.Namespace)).SetLastEditedAt(at.UTC()).Save(ctx)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the current order follow sql syntax order

@@ -519,6 +520,7 @@ func MapSubscriptionViewToAPI(view subscription.SubscriptionView) (api.Subscript
UpdatedAt: apiSub.UpdatedAt,
Status: apiSub.Status,
Alignment: &alg,
IsCustom: apiSub.IsCustom,
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 expose EditedAt as well on the API?

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, but then we commit to it in this form

@GAlexIHU GAlexIHU requested a review from tothandras March 11, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants