Skip to content

postgres - feat: better ttl support#1861

Merged
jaredwray merged 4 commits intomainfrom
postgres---feat-better-ttl-support
Feb 22, 2026
Merged

postgres - feat: better ttl support#1861
jaredwray merged 4 commits intomainfrom
postgres---feat-better-ttl-support

Conversation

@jaredwray
Copy link
Owner

@jaredwray jaredwray commented Feb 22, 2026

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
postgres - feat: better ttl support

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jaredwray, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the PostgreSQL Keyv adapter by introducing robust Time-To-Live (TTL) support. It modifies the database schema to include an 'expires' column, ensuring that expiration timestamps are stored directly in the database. The 'set' and 'setMany' operations are updated to automatically populate this column, allowing for better management of cached data with expiration policies. This change improves the adapter's functionality for managing transient data.

Highlights

  • TTL Column Addition: A new 'expires' column of type 'BIGINT' has been added to the PostgreSQL table schema to store expiration timestamps.
  • Automatic Expiration Handling: The 'set' and 'setMany' methods now automatically extract and store the 'expires' timestamp from the value being stored, if present.
  • Migration and Indexing: The database migration script and the 'KeyvPostgres' initialization logic have been updated to idempotently add the 'expires' column and create an index on it for efficient querying.
  • Robust Expiration Extraction: A new helper method 'getExpiresFromValue' was introduced to reliably parse expiration timestamps from various value formats (JSON strings, objects, etc.).
Changelog
  • storage/postgres/scripts/migrate-v6.ts
    • Added an 'expires' column to the database table during the v6 migration process.
  • storage/postgres/src/index.ts
    • Modified table creation SQL to include the 'expires' column.
    • Introduced a new migration step to add the 'expires' column idempotently.
    • Added an index on the 'expires' column for efficient TTL management.
    • Updated the 'init' method to incorporate the new 'expires' column migration and index creation.
    • Integrated 'expires' column into the 'set' operation's upsert query.
    • Extended 'setMany' operation to handle and store expiration timestamps for multiple entries.
    • Implemented a new private helper method 'getExpiresFromValue' to extract expiration timestamps from various value formats.
  • storage/postgres/test/test.ts
    • Added comprehensive test cases for 'set' and 'setMany' operations to verify correct 'expires' column handling.
    • Included tests for various scenarios such as null expires, non-JSON values, upserts, and object values.
    • Verified integration with Keyv core's TTL functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces better TTL support for the PostgreSQL adapter by adding a dedicated expires column to the database. This allows for more efficient handling and querying of expiring keys. The changes include updating the table schema, modifying the set and setMany methods to populate the new column, and adding a migration script. The accompanying tests are thorough and cover various scenarios. The implementation is solid. I've added one suggestion to improve the readability of a new helper function.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99e4e90cb7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.96%. Comparing base (c6da777) to head (c71498c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1861   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files          32       32           
  Lines        2548     2589   +41     
  Branches      452      458    +6     
=======================================
+ Hits         2547     2588   +41     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jaredwray jaredwray merged commit 0aecdfc into main Feb 22, 2026
8 checks passed
@jaredwray jaredwray deleted the postgres---feat-better-ttl-support branch February 22, 2026 23:51
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.

1 participant