Skip to content

Add PostgreSQL repository package#19

Merged
dahlia merged 13 commits intofedify-dev:mainfrom
dahlia:postgres
Mar 30, 2026
Merged

Add PostgreSQL repository package#19
dahlia merged 13 commits intofedify-dev:mainfrom
dahlia:postgres

Conversation

@dahlia
Copy link
Copy Markdown
Member

@dahlia dahlia commented Mar 30, 2026

This PR adds a new PostgreSQL-backed repository package, @fedify/botkit-postgres, for BotKit.

The package introduces PostgresRepository, PostgresRepositoryOptions, and initializePostgresRepositorySchema(), with support for either an injected Postgres.js client or an internally managed connection pool, configurable schema names, and optional prepared statement disabling for PgBouncer-style deployments.

The implementation includes integration coverage for repository persistence, follower management, schema initialization, prepared statement configuration, and concurrency-sensitive follow/unfollow flows in shared multi-worker deployments.

This PR also updates the PostgreSQL repository documentation and package metadata so the package is publishable and consumable from npm, and so its generated declaration files remain valid for stricter TypeScript consumers.

Closes #11

Testing:

  • POSTGRES_URL=postgresql://localhost/botkit deno test --allow-env --allow-net=localhost,127.0.0.1 packages/botkit-postgres/src/mod.test.ts

  • POSTGRES_URL=postgresql://localhost/botkit pnpm --filter @fedify/botkit-postgres test

  • pnpm pack --pack-destination ../../.tmp-pack (verified the packed package.json and generated dist/mod.d.ts)

dahlia added 9 commits March 30, 2026 15:41
Add @fedify/botkit-postgres as a PostgreSQL-backed Repository
implementation for BotKit, including schema initialization,
connection ownership handling, and integration tests guarded by
POSTGRES_URL.

Update the repository documentation and changelog so the new
package and its configuration model are documented alongside the
existing repository backends.

Closes fedify-dev#11
Handle schema initialization failures without triggering
unhandled rejection warnings before callers await repository
operations.

Preserve follower state when removing one follow request if the
same actor still has other follow requests, and add regression
tests for both behaviors.
Pass the repository's prepare setting through schema
initialization so PostgreSQL deployments that disable prepared
statements behave consistently during startup.

Add regression coverage for both the public schema helper and
the repository constructor path, and document the helper's
third argument for PgBouncer-style setups.
Remove stale follower rows when an existing follow request ID
is repointed at a different actor, so follower counts,
membership checks, and follower iteration stay consistent with
the remaining follow request mappings.

Add a regression test that reproduces the reassignment case and
record the fix in the changelog for the PostgreSQL repository.

fedify-dev#11
Guard addFollower() with a follow-request-scoped advisory lock
so concurrent workers cannot both observe an unassigned follow
request and leave behind a stale follower row.

Add a regression test that forces the racing assignment window
across two PostgreSQL clients, and record the fix in the
changelog.

Closes fedify-dev#11
Guard removeFollower() with the same follow-request-scoped
advisory lock used by addFollower() so an Undo(Follow) cannot
race ahead of an in-flight follow acceptance and leave a stale
follower behind.

Add a regression test that forces the add/remove interleaving
across two PostgreSQL clients, and record the fix in the
changelog.

Closes fedify-dev#11
Lock follower cleanup by previous follower ID so concurrent
reassignment of multiple follow requests away from the same
actor cannot leave a stale follower row behind.

Factor the cleanup path through a shared helper, add a
regression test that forces the concurrent reassignment window,
and record the fix in the changelog.

Closes fedify-dev#11
Replace workspace and catalog dependency specifiers in the
PostgreSQL package metadata with publishable semver ranges so
npm consumers can install the package without unsupported
protocol errors.

Move the Temporal polyfill setup out of tsdown's bundle intro
and into runtime source initialization so generated
declaration files stay valid for strict TypeScript consumers.

Closes fedify-dev#11
Condense the unreleased changelog entry for
@fedify/botkit-postgres to describe the package's initial
feature set instead of listing internal bug-fix iterations
that users have never seen in a released version.
@dahlia dahlia added the enhancement New feature or request label Mar 30, 2026
@dahlia dahlia self-assigned this Mar 30, 2026
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 30, 2026

@codex review

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 3.10458% with 593 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/botkit-postgres/src/mod.ts 3.10% 591 Missing and 2 partials ⚠️
Files with missing lines Coverage Δ
packages/botkit-postgres/src/mod.ts 3.10% <3.10%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@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 the @fedify/botkit-postgres package, which provides a PostgreSQL-based repository implementation for BotKit using the postgres.js driver. The new PostgresRepository supports persistent storage for key pairs, messages, followers, and poll votes, featuring concurrency control through advisory locks. The PR also includes updated documentation, integration tests, and necessary dependency updates. I have no feedback to provide.

Copy link
Copy Markdown

@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: 658351defa

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

Acquire follower-level advisory locks in addFollower() before writing
followers and follow_requests so cleanup and inserts cannot race on
the same actor key.

Add a regression test that reproduces concurrent reassignment plus
new follow insertion and verifies valid follower state is retained.

fedify-dev#19 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 30, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 30, 2026

/gemini review

@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini is experiencing higher than usual traffic and was unable to create the review. Please try again in a few hours by commenting /gemini review.

Copy link
Copy Markdown

@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: d95cd4a8e4

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

dahlia and others added 2 commits March 30, 2026 19:22
Treat url and maxConnections as conflicting with sql only when
they have non-null values, so option spreads that preserve
undefined fields do not fail at runtime.

Add a regression assertion that verifies undefined mutually
exclusive fields remain accepted.

fedify-dev#19 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
Enable workspace linking for semver-compatible local packages so
pnpm install resolves the in-repo @fedify/botkit package instead of
failing against the registry for the unreleased 0.4.0 range.

Refresh pnpm-lock.yaml after the workspace resolution change.

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 30, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 30, 2026

/gemini review

Copy link
Copy Markdown

@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 a new PostgreSQL-backed repository package, @fedify/botkit-postgres, which provides persistent storage for BotKit using the PostgresRepository class. The implementation includes schema initialization, support for both Deno and Node.js runtimes, and concurrency control via PostgreSQL advisory locks. Feedback was provided regarding the global polyfilling of the Temporal API, which contradicts the package's sideEffects: false metadata and should be moved to consumer responsibility. Additionally, a performance optimization was suggested to add a composite index on the poll_votes table to improve the efficiency of voter counting queries.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

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

The package applies Temporal polyfills at module load time, so its
package metadata must not advertise the module as side-effect free.

Set sideEffects to true so bundlers preserve the initialization when
consumers import the package.

fedify-dev#19 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 30, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 30, 2026

/gemini review

Copy link
Copy Markdown

@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 the @fedify/botkit-postgres package, providing a PostgreSQL-backed repository implementation for BotKit. The changes include the PostgresRepository class, schema initialization logic, and comprehensive integration tests, along with updated documentation. Feedback was provided regarding a micro-optimization in the internal execute function to avoid unnecessary array allocations by using a type assertion instead of the spread operator when passing parameters to the database driver.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

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

@dahlia dahlia merged commit 5ce2916 into fedify-dev:main Mar 30, 2026
3 of 4 checks passed
@dahlia dahlia deleted the postgres branch March 30, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PostgreSQL repository implementation

1 participant