Repository navigation
ci: run the integration tests on Postgres - #123
Merged
Merged
Conversation
Adds pnpm test:postgres (DATABASE_ADAPTER=postgres), a database adapter helper that gives every Payload instance of a test run its own Postgres database, a global setup that drops them afterwards, and the CI job "Test (Postgres)" with a postgres:16 service. Nine tests that fail on Postgres because the collection hooks work outside the request's transaction are marked as expected failures there. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0122PV8TJ7ELGdAX7H2hdrRU
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Postgres is the adapter that always runs Payload's operations in a transaction, and the tests only ran on SQLite, where there are none by default. Work the plugin does outside the request's transaction only shows up on Postgres.
What
pnpm test:postgresruns the same vitest suite withDATABASE_ADAPTER=postgresagainst the server inDATABASE_URI.dev/helpers/databaseAdapter.tspicks the adapter fordev/payload.config.tsand the four spec files that build their own config. On Postgres every Payload instance of a run gets its own database (pb_test_<run>_<pid>_<name>, created by Payload's adapter on connect);dev/helpers/postgresGlobalSetup.tsdrops them after the run.postgresjob, Test (Postgres), with apostgres:16service. No PostGIS is needed: the plugin has no point fields.dev/README.mdanddev/.env.exampledescribe the new script.No published source changes.
@payloadcms/db-postgreswas already a devDependency.What the Postgres run found
Nine tests fail on Postgres, all from one defect in the plugin: the collection hooks of refunds, invoices and payments read and write related documents without the request they were given, so that work runs outside the request's transaction.
paymentset, locks the payment's row until the transaction ends (foreign key). The hook then updates that payment on another connection and waits for the transaction, which is waiting for the hook. The request hangs.succeeded, the hook that derives the payment'srefunded/partially_refundedstatus does not see the refund being saved, so the payment stayssucceeded.Fixing it changes how hook failures behave inside a transaction and needs its own PR, so this one does not touch
src. Instead:testFailingOnPostgres(dev/helpers/knownPostgresDefects.ts): plainteston SQLite,test.failson Postgres, so the Postgres job turns red as soon as the defect is fixed and the marker has to go. No assertion was changed.lock_timeout=3000, so the self-deadlock is an error after three seconds instead of a test timeout with two stuck connections.Verified locally
Postgres 16: 275 passed, 9 expected fail (284). SQLite: 284 passed.
🤖 Generated with Claude Code
https://claude.ai/code/session_0122PV8TJ7ELGdAX7H2hdrRU