Skip to content

feat: capture invoice snapshot date - #2829

Merged
turip merged 1 commit into
mainfrom
feat/capture-invoice-snapshot-date
May 16, 2025
Merged

turip merged 1 commit into
mainfrom
feat/capture-invoice-snapshot-date

Conversation

@turip

@turip turip commented May 16, 2025 •

Copy link
Copy Markdown
Member

Overview

Draft invoices have their quantities snapshotted during creation. This patch captures it into the invoice header for non-gathering invoices.

This will enable us to move the collection to the draft state.

Summary by CodeRabbit

  • New Features

    • Added a new timestamp field, "quantitySnapshotedAt," to invoices, indicating when the quantity snapshots on invoice lines were taken. This field is now visible in API responses and user interfaces where invoice details are shown.
  • Database

    • The invoices database now includes the "quantity_snapshoted_at" column, with existing records backfilled where appropriate.
  • Bug Fixes

    • None.
  • Chores

    • Updated documentation and schema definitions to reflect the new invoice field.

@turip
turip requested a review from a team as a code owner May 16, 2025 09:09
@turip
turip enabled auto-merge (squash) May 16, 2025 09:09
@coderabbitai

coderabbitai Bot commented May 16, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new optional timestamp field, quantitySnapshotedAt, was introduced to the invoice data model across the codebase, API schemas, and database. This field records when quantity snapshots on invoice lines were taken. The update includes schema changes, database migrations, API/interface updates, and corresponding logic for setting, persisting, and querying this new field.

Changes

Files / Paths Change Summary
api/client/javascript/src/client/schemas.ts
api/openapi.cloud.yaml
api/openapi.yaml
api/spec/src/billing/invoices/invoice.tsp
Added an optional, read-only quantitySnapshotedAt timestamp property to the Invoice schema/interface/model with description and example.
openmeter/billing/invoice.go
openmeter/ent/db/billinginvoice.go
openmeter/ent/schema/billing.go
Added optional field QuantitySnapshotedAt of type *time.Time to invoice-related structs/schemas, with JSON and database integration.
openmeter/billing/adapter/invoice.go
openmeter/billing/httpdriver/invoice.go
Updated invoice mapping and update logic to handle the new QuantitySnapshotedAt field for persistence and API exposure.
openmeter/billing/service/invoice.go
openmeter/billing/service/invoiceline.go
Set QuantitySnapshotedAt to the current time during invoice recalculation and line association processes.
openmeter/ent/db/billinginvoice/billinginvoice.go Added constant, column, and ordering function for quantity_snapshoted_at in the billing invoice entity.
openmeter/ent/db/billinginvoice/where.go Introduced predicate functions for querying/filtering by quantity_snapshoted_at timestamp.
openmeter/ent/db/billinginvoice_create.go Added setter methods for quantity_snapshoted_at in create and upsert builders for the billing invoice entity.
openmeter/ent/db/billinginvoice_update.go Added setter and clearer methods for quantity_snapshoted_at in update builders for the billing invoice entity.
openmeter/ent/db/setorclear.go Added SetOrClearQuantitySnapshotedAt methods to update builders for conditional setting/clearing.
openmeter/ent/db/mutation.go Extended mutation struct and logic to support quantity_snapshoted_at field, including setters, getters, clearing, and reset functionality.
openmeter/ent/db/migrate/schema.go Added a nullable time column quantity_snapshoted_at to the billing invoices table schema, updating indices accordingly.
openmeter/ent/db/runtime.go Adjusted field indices in schema descriptor assignments due to the new column.
tools/migrate/migrations/20250516090128_billing-invoice-snapshotted-at.up.sql
tools/migrate/migrations/20250516090128_billing-invoice-snapshotted-at.down.sql
Migration scripts to add and remove the quantity_snapshoted_at column in the billing_invoices table, including backfill logic for existing records.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@turip turip added release-note/feature Release note: Exciting New Features area/billing labels May 16, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
openmeter/billing/service/invoiceline.go (1)

356-356: Good use of UTC for timestamp consistency in billing data.

Setting QuantitySnapshotedAt to UTC time after snapshotting all line quantities ensures consistent timestamp storage, which is important for billing data that may be used across different time zones.

Consider standardizing UTC usage across all timestamp assignments. In invoice.go, there's a similar assignment that uses clock.Now() without explicit UTC conversion:

-invoice.QuantitySnapshotedAt = lo.ToPtr(now)
+invoice.QuantitySnapshotedAt = lo.ToPtr(now.UTC())
api/spec/src/billing/invoices/invoice.tsp (1)

141-146: Add read-only snapshot timestamp: The new quantitySnapshotedAt field is correctly introduced with @visibility(Lifecycle.Read) and a clear description. Please verify that the corresponding OpenAPI specs (api/openapi.yaml, api/openapi.cloud.yaml) and the JavaScript client schema have been updated to include this property.
Minor nit: consider whether “quantitySnapshotedAt” is the most intuitive name (e.g., quantitySnapshotAt or quantitySnapshotTakenAt) for consistency and readability.

api/openapi.cloud.yaml (1)

15318-15323: Consider nullability for invoices without snapshots.
If invoices in the gathering state should explicitly return null instead of omitting the field, consider marking the property as nullable. For example:

 quantitySnapshotedAt:
+  nullable: true
   type: string
   format: date-time
   description: The time when the quantity snapshots on the invoice lines were taken.
   example: '2023-01-01T01:01:01.001Z'
   readOnly: true
api/openapi.yaml (1)

15428-15433: Explicitly allow null for quantitySnapshotedAt and sync cloud spec
The new read-only quantitySnapshotedAt field is correctly defined, but since it won’t be set for gathering-state invoices, consider marking it as nullable: true to explicitly allow null values. Also verify that this property has been added to api/openapi.cloud.yaml to keep both API specs in sync.

Proposed diff:

   quantitySnapshotedAt:
     type: string
     format: date-time
+    nullable: true
     description: The time when the quantity snapshots on the invoice lines were taken.
     example: '2023-01-01T01:01:01.001Z'
     readOnly: true
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1705591 and 8921ac6.

⛔ Files ignored due to path filters (1)
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum
📒 Files selected for processing (21)
  • api/client/javascript/src/client/schemas.ts (1 hunks)
  • api/openapi.cloud.yaml (1 hunks)
  • api/openapi.yaml (1 hunks)
  • api/spec/src/billing/invoices/invoice.tsp (1 hunks)
  • openmeter/billing/adapter/invoice.go (2 hunks)
  • openmeter/billing/httpdriver/invoice.go (1 hunks)
  • openmeter/billing/invoice.go (1 hunks)
  • openmeter/billing/service/invoice.go (1 hunks)
  • openmeter/billing/service/invoiceline.go (2 hunks)
  • openmeter/ent/db/billinginvoice.go (4 hunks)
  • openmeter/ent/db/billinginvoice/billinginvoice.go (3 hunks)
  • openmeter/ent/db/billinginvoice/where.go (2 hunks)
  • openmeter/ent/db/billinginvoice_create.go (5 hunks)
  • openmeter/ent/db/billinginvoice_update.go (4 hunks)
  • openmeter/ent/db/migrate/schema.go (3 hunks)
  • openmeter/ent/db/mutation.go (10 hunks)
  • openmeter/ent/db/runtime.go (1 hunks)
  • openmeter/ent/db/setorclear.go (1 hunks)
  • openmeter/ent/schema/billing.go (2 hunks)
  • tools/migrate/migrations/20250516090128_billing-invoice-snapshotted-at.down.sql (1 hunks)
  • tools/migrate/migrations/20250516090128_billing-invoice-snapshotted-at.up.sql (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (10)
openmeter/billing/service/invoice.go (1)
openmeter/ent/db/billinginvoice/where.go (1)
  • QuantitySnapshotedAt (255-257)
openmeter/billing/service/invoiceline.go (2)
openmeter/ent/db/billinginvoice/where.go (1)
  • QuantitySnapshotedAt (255-257)
pkg/clock/clock.go (1)
  • Now (14-21)
openmeter/billing/httpdriver/invoice.go (3)
openmeter/ent/db/billinginvoice/where.go (9)
  • CreatedAt (78-80)
  • UpdatedAt (83-85)
  • DeletedAt (88-90)
  • IssuedAt (240-242)
  • VoidedAt (235-237)
  • DueAt (266-268)
  • DraftUntil (250-252)
  • SentToCustomerAt (245-247)
  • QuantitySnapshotedAt (255-257)
openmeter/billing/invoiceline.go (1)
  • Period (83-86)
api/api.gen.go (1)
  • Period (5433-5439)
openmeter/billing/invoice.go (1)
openmeter/ent/db/billinginvoice/where.go (8)
  • CreatedAt (78-80)
  • UpdatedAt (83-85)
  • VoidedAt (235-237)
  • DraftUntil (250-252)
  • IssuedAt (240-242)
  • DeletedAt (88-90)
  • SentToCustomerAt (245-247)
  • QuantitySnapshotedAt (255-257)
openmeter/ent/db/migrate/schema.go (1)
openmeter/ent/db/billinginvoice/billinginvoice.go (1)
  • Columns (204-260)
openmeter/billing/adapter/invoice.go (3)
pkg/convert/ptr.go (1)
  • SafeToUTC (36-40)
openmeter/ent/db/billinginvoice/where.go (9)
  • QuantitySnapshotedAt (255-257)
  • ID (18-20)
  • Namespace (73-75)
  • Currency (260-263)
  • Number (215-217)
  • Description (220-222)
  • DueAt (266-268)
  • DraftUntil (250-252)
  • SentToCustomerAt (245-247)
pkg/convert/time.go (1)
  • TimePtrIn (5-10)
openmeter/ent/db/setorclear.go (1)
openmeter/ent/db/billinginvoice_update.go (2)
  • BillingInvoiceUpdate (25-29)
  • BillingInvoiceUpdateOne (1398-1403)
openmeter/ent/db/billinginvoice/where.go (3)
openmeter/ent/schema/billing.go (5)
  • BillingInvoice (699-701)
  • BillingInvoice (703-718)
  • BillingInvoice (720-853)
  • BillingInvoice (855-867)
  • BillingInvoice (869-911)
openmeter/ent/db/predicate/predicate.go (1)
  • BillingInvoice (65-65)
openmeter/ent/db/billinginvoice/billinginvoice.go (1)
  • FieldQuantitySnapshotedAt (98-98)
openmeter/ent/db/billinginvoice_update.go (2)
openmeter/ent/db/billinginvoice/where.go (1)
  • QuantitySnapshotedAt (255-257)
openmeter/ent/db/billinginvoice/billinginvoice.go (1)
  • FieldQuantitySnapshotedAt (98-98)
openmeter/ent/db/billinginvoice_create.go (2)
openmeter/ent/db/billinginvoice/where.go (1)
  • QuantitySnapshotedAt (255-257)
openmeter/ent/db/billinginvoice/billinginvoice.go (1)
  • FieldQuantitySnapshotedAt (98-98)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: E2E
  • GitHub Check: CI
  • GitHub Check: Analyze (go)
🔇 Additional comments (43)
tools/migrate/migrations/20250516090128_billing-invoice-snapshotted-at.down.sql (1)

1-2: The down migration is correctly implemented.

The SQL statement properly drops the quantity_snapshoted_at column from the billing_invoices table, providing a clean rollback path for the feature.

openmeter/billing/service/invoice.go (1)

160-161: Recording snapshot timestamp before calculation is a good approach.

Setting QuantitySnapshotedAt at this point ensures the timestamp accurately reflects when invoice quantities were captured, just before the invoice calculations are performed.

openmeter/billing/invoice.go (1)

282-282: New timestamp field properly follows established conventions.

The QuantitySnapshotedAt field is correctly defined as a pointer type consistent with other optional timestamp fields, includes appropriate JSON tags with omitempty, and is well-placed among related timestamp fields.

api/openapi.cloud.yaml (1)

15318-15323: Schema addition looks correct.
The new quantitySnapshotedAt property is well-defined as a read-only date-time field with a clear description and example, accurately capturing when invoice line quantities were snapshotted.

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

5193-5198:

Details

❓ Verification inconclusive

Confirm quantitySnapshotedAt consistency and mapping
The new optional quantitySnapshotedAt?: Date property is correctly defined with matching JSDoc. Please ensure that:

  1. The spelling and casing of this field exactly match the OpenAPI specs (api/openapi.yaml & api/openapi.cloud.yaml) and the backend model.
  2. The client-side JSON→TS transformer (mapper) handles this new date-time field and converts the incoming ISO string into a Date object.

🏁 Script executed:

#!/usr/bin/env bash
# Verify consistency of 'quantitySnapshotedAt' across specs and client code
rg -n "quantitySnapshotedAt" api/openapi.yaml api/openapi.cloud.yaml api/client/javascript/src/client

Length of output: 305


🏁 Script executed:

#!/usr/bin/env bash
# Show the surrounding interface and mapper for `quantitySnapshotedAt`
sed -n '5170,5230p' api/client/javascript/src/client/schemas.ts

Length of output: 2831


Confirm JSON→TS mapping for quantitySnapshotedAt
We’ve verified that quantitySnapshotedAt is defined in both api/openapi.yaml and api/openapi.cloud.yaml (lines 15428/15318) and in api/client/javascript/src/client/schemas.ts. Please double-check that your JSON→TS transformer (mapper) includes this field and converts the incoming ISO string into a Date, for example:

// in your Invoice mapper
quantitySnapshotedAt: raw.quantitySnapshotedAt
  ? new Date(raw.quantitySnapshotedAt)
  : undefined,
  • If you use a generic date mapping utility, ensure it’s applied to this new property.
  • If you hand-roll mappers for each schema, add the above line to the Invoice mapper.
openmeter/billing/httpdriver/invoice.go (1)

491-499: LGTM: The new timestamp field is correctly added to the API response.

The addition of QuantitySnapshotedAt field to the invoice API response is correctly implemented, maintaining consistency with other timestamp fields in the struct. This change properly exposes the new field that tracks when quantity snapshots on invoice lines were taken.

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

775-778: LGTM: New field properly defined in the database schema.

The addition of the quantity_snapshoted_at field to the BillingInvoice schema is correctly implemented. The field is appropriately defined as optional and nullable, which is suitable for a timestamp that might not be set for all invoices. This aligns with the PR objective of capturing invoice quantity snapshot dates.

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

483-488: Index updates correctly reflect the new field addition.

The modified indices for billinginvoiceDescCurrency and billinginvoiceDescCollectionAt are necessary accommodations for the insertion of the new quantity_snapshoted_at field in the schema. These adjustments ensure proper field descriptor mappings are maintained after the schema change.

openmeter/billing/adapter/invoice.go (2)

455-455: Added proper handling for the new quantitySnapshotedAt field.

The implementation correctly uses the SetOrClearQuantitySnapshotedAt method with convert.SafeToUTC to handle nullable timestamps. This ensures proper timezone handling when updating invoice data.


647-647: Added mapping for the new field in the response structure.

The implementation correctly maps the database field to the domain model using convert.TimePtrIn with UTC timezone, maintaining consistency with how other datetime fields are handled.

tools/migrate/migrations/20250516090128_billing-invoice-snapshotted-at.up.sql (3)

1-3: Added nullable timestamp column for quantity snapshot tracking.

The migration correctly adds quantity_snapshoted_at as a nullable timestamp column, which is appropriate for an optional field.


4-9: Sensible backfill strategy for existing invoices.

The migration includes a well-commented backfill strategy that sets quantity_snapshoted_at to created_at only for non-gathering invoices. The comment clearly explains why gathering invoices are excluded from the backfill.


1-9:

Details

✅ Verification successful

Verify consistent naming convention across the codebase.

I notice the field name uses "snapshoted" rather than "snapshotted" (with two 'p's). While either could be valid, ensure this spelling is used consistently throughout the codebase, documentation, and API.


🏁 Script executed:

#!/bin/bash
# Check for consistency in spelling of "snapshoted" vs "snapshotted" across the codebase

echo "Checking for 'snapshoted' usage:"
rg -i "snapshoted" --type=go --type=sql --type=typescript --type=yaml

echo -e "\nChecking for 'snapshotted' usage:"
rg -i "snapshotted" --type=go --type=sql --type=typescript --type=yaml

Length of output: 380


🏁 Script executed:

#!/bin/bash
# Re-run spelling check without file-type filters to capture all occurrences

echo "Searching for 'snapshoted' across all files..."
rg -i "snapshoted" || echo "No matches for 'snapshoted'"

echo -e "\nSearching for 'snapshotted' across all files..."
rg -i "snapshotted" || echo "No matches for 'snapshotted'"

Length of output: 24081


No inconsistencies found for the invoice field spelling

The column/field quantity_snapshoted_at is spelled “snapshoted” everywhere in the invoice code paths (migrations, Ent schema, DB models, service, HTTP driver, OpenAPI spec and generated clients).
Occurrences of “snapshotted” appear only in the balance‐snapshot domain (e.g. SnapshottedUsage), which is a separate concept and not related to the invoice field. No changes required here.

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

842-855: LGTM! Well-implemented field operations for the new quantity snapshot timestamp.

The new SetOrClearQuantitySnapshotedAt methods for both BillingInvoiceUpdate and BillingInvoiceUpdateOne follow the established pattern in this file, properly handling nil values and maintaining the fluent interface pattern with appropriate return types. This implementation aligns well with the PR objective of capturing invoice snapshot dates.

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

600-600: Well-integrated field addition to invoice schema

The new nullable timestamp column quantity_snapshoted_at has been properly added to the BillingInvoicesColumns. This field correctly aligns with the PR objective to capture the snapshot date of invoice quantities.


625-656: Foreign key indices correctly updated

The foreign key references have been properly incremented to accommodate the new column position in the table. This ensures that all relationships are maintained correctly after adding the new field.


680-691: Index references correctly updated

The index references have been appropriately adjusted to account for the insertion of the new field, ensuring that all indexes point to the correct columns after the schema change.

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

107-108: Field properly added to BillingInvoice struct

The new QuantitySnapshotedAt field has been correctly added to the struct with proper documentation and JSON tags. This implementation matches the database schema change.


261-261: Field correctly added to scanValues handler

The QuantitySnapshotedAt field has been appropriately added to the list of time fields in the scanValues method, ensuring that it will be properly scanned from database results as a sql.NullTime.


543-549: Assignment logic correctly implemented

The assignment logic for the new field has been properly implemented in the assignValues method, including type checking and validity checks. This ensures proper conversion from the database value to the struct field.


877-881: String representation appropriately updated

The String() method has been updated to include the string representation of the new field when it's non-nil, ensuring that the field is properly represented in string output.

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

97-98: Addition of new QuantitySnapshotedAt field constant.

The new field constant is properly documented and follows the naming convention used throughout the codebase.


245-245: Adding QuantitySnapshotedAt to Columns array.

Correctly adds the new field to the Columns slice to ensure it's recognized as a valid column for the entity.


514-517: Implementation of ByQuantitySnapshotedAt ordering function.

The ordering function follows the same pattern as other field ordering functions, making the field available for sorting in queries.

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

635-653: Added setter and clearer methods for QuantitySnapshotedAt in BillingInvoiceUpdate.

These methods provide the standard interface for setting, conditionally setting, and clearing the new timestamp field, following the same pattern as other fields.


1209-1214: Updated sqlSave to handle QuantitySnapshotedAt field changes.

The implementation correctly handles both setting and clearing the field in SQL update operations.


2003-2021: Added setter and clearer methods for QuantitySnapshotedAt in BillingInvoiceUpdateOne.

These methods follow the same pattern as in BillingInvoiceUpdate, maintaining consistency throughout the codebase.


2607-2612: Updated BillingInvoiceUpdateOne.sqlSave to handle QuantitySnapshotedAt field.

The implementation properly handles both setting and clearing the field in SQL update operations for single entity updates.

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

11431-11431: Field addition looks good.

The new nullable timestamp field quantity_snapshoted_at follows the same pattern as other timestamp fields in the struct and is properly positioned within the field list.


13260-13307: Accessor methods are complete and follow established patterns.

All necessary mutation methods for the new field have been implemented, following the same pattern as other timestamp fields:

  • Setter and getter methods
  • Old value retrieval with proper error handling
  • Clear and reset functionality
  • Status checking methods

These implementations maintain consistency with the codebase patterns.


14247-14247: Capacity adjustment is appropriate.

The fields slice capacity was increased to accommodate the additional field.


14365-14367: Field collection logic looks good.

The field is properly included in the Fields() method when it has been set.


14496-14497: Field accessor case added correctly.

The new field case was added to the Field() method's switch statement.


14613-14614: Old field accessor case added correctly.

The new field case was added to the OldField() method's switch statement.


14925-14931: Field setter case added with proper type checking.

The SetField() method includes the new field with appropriate type checking to ensure the value is a time.Time.


15126-15128: Cleared field tracking is properly implemented.

The field is correctly included in the list of cleared fields when appropriate.


15233-15235: Field clearing case added correctly.

The new field case was added to the ClearField() method's switch statement.


15385-15387: Field reset case added correctly.

The new field case was added to the ResetField() method's switch statement.

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

454-466: Properly implemented quantitySnapshotedAt field setters for creation operations.

The implementation correctly adds setter methods for the new quantity_snapshoted_at timestamp field, following the established pattern in the codebase - one method for direct setting and another for conditionally setting non-nil values.


1078-1081: Correctly integrated field into SQL specification.

The field is properly added to the SQL insert specification, which ensures it's correctly persisted to the database during entity creation.


1860-1876: Properly implemented upsert operations for the new field.

The implementation follows the same pattern as other fields, adding the necessary methods for setting, updating, and clearing the quantity_snapshoted_at field during upsert operations.


3862-3881: Properly implemented bulk upsert operations for the new field.

The implementation correctly adds support for the new field in bulk upsert operations, maintaining consistency with the existing pattern for other fields.

openmeter/ent/db/billinginvoice/where.go (1)

254-647: Implementation for new quantitySnapshotedAt field looks correct and follows established patterns.

The added predicate functions for the quantity_snapshoted_at field follow the same pattern as other timestamp fields, providing a complete set of equality, comparison, inclusion, and null-checking operations that will enable flexible querying based on this new timestamp.

Comment thread api/openapi.cloud.yaml
Comment on lines +15318 to +15323
quantitySnapshotedAt:
type: string
format: date-time
description: The time when the quantity snapshots on the invoice lines were taken.
example: '2023-01-01T01:01:01.001Z'
readOnly: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Ensure consistent inclusion across API specs.
Please verify that quantitySnapshotedAt is also present in the core api/openapi.yaml, client schemas, and any generated SDKs to maintain full parity.

Run this script from the repo root to confirm:


🏁 Script executed:

#!/bin/bash
# Verify that the field exists in all OpenAPI specs
rg -n "quantitySnapshotedAt" -C2 api/openapi*

Length of output: 733


quantitySnapshotedAt present in core and cloud specs; update client SDKs

We’ve confirmed that quantitySnapshotedAt exists in both API specs:

  • api/openapi.yaml (line 15428)
  • api/openapi.cloud.yaml (line 15318)

Next steps to maintain parity:

  • Regenerate all client schemas and SDKs (e.g., via your standard codegen command).
  • Inspect the generated models (e.g., the InvoiceLine type/interface) to ensure quantitySnapshotedAt is included.

No further spec changes are needed.

🤖 Prompt for AI Agents
In api/openapi.cloud.yaml around lines 15318 to 15323, the field
quantitySnapshotedAt is correctly defined and also present in the core
api/openapi.yaml at line 15428. To maintain parity, regenerate all client
schemas and SDKs using the standard code generation commands. After
regeneration, verify that the quantitySnapshotedAt field is included in the
generated models such as the InvoiceLine type or interface. No changes to the
spec files are needed.

issued_at *time.Time
sent_to_customer_at *time.Time
draft_until *time.Time
quantity_snapshoted_at *time.Time

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify consistent spelling across the codebase.

The field name uses "snapshoted" (with one 't') rather than the more common spelling "snapshotted" (with two 't's). This appears to be a consistent choice across the codebase based on the PR summary, but it's worth confirming that this spelling is used consistently throughout all related changes.

Also applies to: 13260-13307


🏁 Script executed:

#!/bin/bash
# Check for consistent spelling of "snapshoted" vs "snapshotted" in the codebase
echo "Checking for spelling consistency across codebase..."
echo "Occurrences of 'snapshoted':"
rg -i "snapshoted" --type go --type sql

echo -e "\nOccurrences of 'snapshotted':"
rg -i "snapshotted" --type go --type sql

Length of output: 22990


Unify “snapshoted” vs. “snapshotted” spelling across the codebase

Your search shows two distinct spellings in use:

  • “snapshoted” (one ‘t’) in billing-invoice code and DB migrations (quantity_snapshoted_at, QuantitySnapshotedAt, etc.)
  • “snapshotted” (two ‘t’s) in balance-snapshot code and tests (SnapshottedUsage, balance_snapshot, etc.)

This inconsistency can lead to confusion and bugs. Please pick one spelling (we recommend the correct “snapshotted”) and update all occurrences:

• Migration files under tools/migrate/migrations/*
• Go structs, JSON tags, and service code in openmeter/billing/...
• Ent schema and generated code under openmeter/ent/schema/… and openmeter/ent/db/... (column names, methods, predicates, mutations, etc.)
• API definitions in api/api.gen.go and api/client/go/client.gen.go

Renaming the DB column will require a new migration and adjustment of all references.

🤖 Prompt for AI Agents
In openmeter/ent/db/mutation.go at line 11431 and also in the range 13260-13307,
there is inconsistent spelling of the term "snapshoted" versus "snapshotted"
across the codebase. To fix this, choose the correct spelling "snapshotted" and
update all occurrences accordingly, including migration files under
tools/migrate/migrations, Go structs, JSON tags, service code in
openmeter/billing, ent schema and generated code under openmeter/ent/schema and
openmeter/ent/db, and API definitions in api/api.gen.go and
api/client/go/client.gen.go. This will require creating a new migration to
rename the database column and updating all references to maintain consistency
and avoid confusion.

@turip
turip merged commit 7241adb into main May 16, 2025
@turip
turip deleted the feat/capture-invoice-snapshot-date branch May 16, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants