Skip to content

Conversation

@mkysel
Copy link
Collaborator

@mkysel mkysel commented May 5, 2025

Add expiry timestamp field to gateway_envelopes table and update related database operations

Introduces a new expiry field of type BIGINT to the gateway_envelopes table through database migrations and updates related SQL operations. The changes include:

📍Where to Start

Start with the database migration file 00011_payload-expiration.up.sql which defines the schema change, then review the SQL query templates in envelopes.sql to understand how the new field is used in database operations.


Macroscope summarized adc9cfd.

Summary by CodeRabbit

  • New Features
    • Added support for an expiry field on gateway envelopes, allowing storage and retrieval of expiration information.
  • Database
    • The database schema now includes an expiry column for gateway envelopes.
  • Bug Fixes
    • No bug fixes included in this release.

@mkysel mkysel requested a review from a team as a code owner May 5, 2025 07:15
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 5, 2025

Walkthrough

The changes introduce support for an expiry field in the gateway_envelopes table and its related data model, queries, and migrations. This includes updating SQL migration scripts to add and remove the expiry column, modifying SQL statements and Go code to handle the new field in insert and select operations, and extending the GatewayEnvelope struct to include the expiry attribute. These updates ensure that the expiry value is consistently managed across database schema, queries, and application data structures.

Changes

File(s) Change Summary
pkg/db/sqlc/envelopes.sql Updated InsertGatewayEnvelope SQL to include the new expiry column in insert operations.
pkg/db/queries/envelopes.sql.go, pkg/db/queries/payerReports.sql.go Updated insert and select queries, method parameters, and scanning logic to handle the expiry field.
pkg/db/queries/models.go Added Expiry sql.NullInt64 field to the GatewayEnvelope struct.
pkg/migrations/00011_payload-expiration.up.sql Added migration to create the expiry column in the gateway_envelopes table.
pkg/migrations/00011_payload-expiration.down.sql Added migration to drop the expiry column from the gateway_envelopes table.

Suggested reviewers

  • fbac

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


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d407e30 and adc9cfd.

📒 Files selected for processing (6)
  • pkg/db/queries/envelopes.sql.go (7 hunks)
  • pkg/db/queries/models.go (1 hunks)
  • pkg/db/queries/payerReports.sql.go (2 hunks)
  • pkg/db/sqlc/envelopes.sql (1 hunks)
  • pkg/migrations/00011_payload-expiration.down.sql (1 hunks)
  • pkg/migrations/00011_payload-expiration.up.sql (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
pkg/db/queries/models.go (1)
pkg/db/types.go (1)
  • NullInt64 (18-20)
pkg/db/queries/envelopes.sql.go (1)
pkg/db/types.go (1)
  • NullInt64 (18-20)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Upgrade Tests
  • GitHub Check: Test (Node)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
🔇 Additional comments (14)
pkg/db/queries/models.go (1)

34-34: Consistent addition of Expiry field

The addition of the Expiry field of type sql.NullInt64 to the GatewayEnvelope struct aligns properly with the database migration that adds the expiry column to the gateway_envelopes table. Using sql.NullInt64 is appropriate since it allows for nullable values in the database.

pkg/migrations/00011_payload-expiration.down.sql (1)

1-2: Proper down migration implementation

The down migration correctly removes the expiry column from the gateway_envelopes table. The use of DROP COLUMN IF EXISTS is a good practice as it ensures the migration won't fail if the column doesn't exist.

pkg/migrations/00011_payload-expiration.up.sql (1)

1-2: Appropriate up migration for expiry column

The migration successfully adds the expiry column as a BIGINT to the gateway_envelopes table. This matches the sql.NullInt64 type used in the Go struct.

Note that the column is implicitly nullable since no NOT NULL constraint is specified, which is consistent with using sql.NullInt64 in the corresponding Go struct.

pkg/db/queries/payerReports.sql.go (2)

79-79: Expiry field added to SELECT query

The SELECT statement has been properly updated to include the new expiry column from the gateway_envelopes table.


100-100: Scan updated to include Expiry field

The row.Scan() call has been correctly updated to populate the Expiry field in the GatewayEnvelope struct, ensuring consistency with the updated query that now includes the expiry column.

pkg/db/sqlc/envelopes.sql (1)

8-9: Expiry field correctly added to InsertGatewayEnvelope query

The implementation properly adds the expiry field to both the column list and values list in the SQL statement, using the @expiry parameter consistently. This aligns with the PR objective of adding an expiry field to gateway envelopes.

Also applies to: 17-18

pkg/db/queries/envelopes.sql.go (8)

83-84: Expiry field correctly added to SQL statement

The SQL statement has been properly updated to include the expiry field in both the column list and values list, maintaining the correct placeholder position ($7) in the query.

Also applies to: 92-93


104-104: Appropriate type used for Expiry field

The Expiry field was correctly added to the InsertGatewayEnvelopeParams struct with type sql.NullInt64, which is appropriate for a field that may be NULL. This is consistent with the approach used for other nullable fields like PayerID.


115-115: Expiry parameter correctly passed to query execution

The Expiry field from the parameter struct is properly passed as an argument to the database execution context, maintaining the correct parameter order.


146-146: SelectGatewayEnvelopes query updated to include expiry field

The SELECT query has been properly updated to explicitly include the expiry field in the selected columns list.


186-186: Scan call updated to populate Expiry field

The rows.Scan call in the SelectGatewayEnvelopes function has been correctly updated to scan the expiry column value into the GatewayEnvelope struct's Expiry field.


202-202: SelectNewestFromTopics query updated to include expiry field

The SELECT statement for retrieving the newest envelopes by topic has been properly updated to include the e.expiry field with the appropriate table alias.


231-231: Scan call in SelectNewestFromTopics updated for Expiry field

The rows.Scan call in the SelectNewestFromTopics function has been correctly updated to include the expiry field, ensuring it's properly populated in the returned envelope structures.


97-105:

Details

✅ Verification successful

Verify that the GatewayEnvelope struct is also updated

The changes to add the Expiry field to the InsertGatewayEnvelopeParams struct look good. Please ensure that the corresponding GatewayEnvelope struct in pkg/db/queries/models.go has also been updated to include the Expiry field of type sql.NullInt64.


🏁 Script executed:

#!/bin/bash
# Check if the GatewayEnvelope struct in models.go has been updated with the Expiry field
rg -A 15 -B 5 "type GatewayEnvelope struct" pkg/db/queries/models.go

Length of output: 507


GatewayEnvelope Struct Updated with Expiry Field

The GatewayEnvelope struct in pkg/db/queries/models.go now includes:

Expiry sql.NullInt64

with the correct type matching InsertGatewayEnvelopeParams. No further changes are needed.

✨ 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.
    • 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.

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.

@@ -0,0 +1,2 @@
ALTER TABLE gateway_envelopes
ADD COLUMN expiry BIGINT; No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the generated go code, it seems this will be set to nil to old rows? Just to take it in account.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct. 0 meens infinite, NULL means it hasn't been set. It requires sophisticated non-sql code to inspect the payload and determine whether it is a commit or not.

@mkysel mkysel merged commit 1aa706b into main May 5, 2025
8 checks passed
@mkysel mkysel deleted the mkysel/add-expiry-field branch May 5, 2025 12:13
@coderabbitai coderabbitai bot mentioned this pull request May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants