Skip to content

postgres - feat: adding in native namespace support#1860

Merged
jaredwray merged 13 commits intomainfrom
postgres---feat-adding-in-native-namespace-support
Feb 22, 2026
Merged

postgres - feat: adding in native namespace support#1860
jaredwray merged 13 commits intomainfrom
postgres---feat-adding-in-native-namespace-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: adding in native namespace 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 KeyvPostgres adapter by introducing native support for namespaces. Instead of relying on key prefixing, a dedicated namespace column is now used in the database table. This change improves data isolation, query performance for namespace-specific operations, and provides a more robust multi-tenancy solution for Keyv users leveraging PostgreSQL. It also includes a migration path for existing installations and comprehensive test coverage.

Highlights

  • Native Namespace Implementation: Introduced a namespace column in the PostgreSQL table schema to natively support Keyv namespaces, moving away from key prefixing.
  • Schema Migration and Indexing: Added logic to automatically migrate existing tables by adding the namespace column, dropping the old primary key, and creating a new unique index on key and namespace for efficient lookups.
  • Namespace-Aware Operations: Modified all data access methods (get, set, delete, clear, iterator, has, etc.) to correctly filter and operate based on the namespace column, ensuring data isolation between different namespaces.
  • Key Prefix Handling: Implemented internal utility functions (_removeKeyPrefix, _getNamespaceValue) to manage Keyv's default key prefixing and map it to the new namespace column for database interactions.
  • Comprehensive Testing: Added new test cases to validate the native namespace functionality, covering independent storage, null namespaces, namespace-specific clearing, and iteration behavior.
Changelog
  • storage/postgres/src/index.ts
    • Updated node:tls import for ConnectionOptions.
    • Modified table creation SQL to include a namespace column with a default NULL value.
    • Added SQL commands for schema migration: ALTER TABLE ADD COLUMN IF NOT EXISTS namespace, DROP CONSTRAINT IF EXISTS pkey, and CREATE UNIQUE INDEX IF NOT EXISTS on key and COALESCE(namespace, '').
    • Adjusted get, getMany, set, setMany, delete, deleteMany, has, hasMany queries to filter by COALESCE(namespace, '').
    • Updated clear logic to delete based on the namespace column or namespace IS NULL.
    • Refactored iterator to query based on the namespace column and re-add the namespace prefix to keys for compatibility.
    • Introduced _removeKeyPrefix to strip Keyv's namespace prefix from keys before database operations.
    • Introduced _getNamespaceValue to provide the correct namespace value for SQL parameters.
  • storage/postgres/src/types.ts
    • Updated ConnectionOptions import to use node:tls.
  • storage/postgres/test/test.ts
    • Added new test cases to verify native namespace functionality, including independent storage for same keys in different namespaces, correct handling of null namespaces, namespace-specific clear operations, and accurate iteration within namespaces.
Activity
  • Added tests for the new native namespace feature, aiming for 100% code coverage.
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.

@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 (73c7a85) to head (be82170).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1860   +/-   ##
=======================================
  Coverage   99.95%   99.96%           
=======================================
  Files          32       32           
  Lines        2493     2548   +55     
  Branches      446      452    +6     
=======================================
+ Hits         2492     2547   +55     
  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.

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: 4af3566d7c

ℹ️ 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".

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 native namespace support for the PostgreSQL adapter, which is a great improvement over the previous LIKE-based emulation. The changes are comprehensive, updating the database schema and all relevant methods (get, set, delete, clear, iterator, etc.) to be namespace-aware. The inclusion of database migration steps in the constructor is a thoughtful touch for backward compatibility. The new tests for native namespaces are also well-written and cover important scenarios.

I've provided a few suggestions to improve the efficiency of the delete and deleteMany methods by using a single atomic query, and to enhance the maintainability of the iterator method's query building logic. Overall, this is a solid feature implementation.

@jaredwray jaredwray merged commit c6da777 into main Feb 22, 2026
10 of 11 checks passed
@jaredwray jaredwray deleted the postgres---feat-adding-in-native-namespace-support branch February 22, 2026 22:10
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