Skip to content

Latest commit

 

History

History
90 lines (64 loc) · 3.97 KB

CONTRIBUTING.md

File metadata and controls

90 lines (64 loc) · 3.97 KB

Contributing

Choosing Between an Issue and a PR

In most cases, a clear bug report or feature request is more helpful than a PR. A PR is helpful when it saves the maintainer time. AI has made code very cheap. If all you did was ask an AI to fix a problem you encountered, please open an issue describing the problem. Include the prompt if it helps. Please skip PRs generated from open-ended prompts like "Find and fix a bug." Even a correct fix can cost more to review and maintain than the problem warrants.

There are a few cases where a PR can provide value.

  • Tiny fixes that obviously are correct (e.g. spelling, punctuation, etc.)
  • Changes where you explored several approaches and can explain the tradeoffs and why you chose this one. If the choice is still open, an issue describing the options may be more useful.
  • Proofs of concept that make a feature request easier to understand, even if the implementation is only for discussion.

Discuss Significant Changes

Before you invest a significant amount of time on a change, please create a discussion or issue describing your proposal. This will help to ensure your proposed change has a reasonable chance of being merged.

Avoid Dependencies

Adding a dependency is a big deal. While on occasion a new dependency may be accepted, the default answer to any change that adds a dependency is no.

Development Environment Setup

pgx tests naturally require a PostgreSQL database. It will connect to the database specified in the PGX_TEST_DATABASE environment variable. The PGX_TEST_DATABASE environment variable can either be a URL or key-value pairs. In addition, the standard PG* environment variables will be respected.

The full environment

DEVELOPMENT.md describes the maintained setup: mise installs the toolchain, and each checkout has its own PostgreSQL 14-18 clusters and CockroachDB node, so the whole test matrix is available locally. PostgreSQL 18 stays running; other servers start and stop around their tests. It works natively on macOS and Linux, and in the included devcontainer.

mise install
mise run dev:init
mise run dev
./test.sh all

Using an existing PostgreSQL cluster

If you already have a PostgreSQL development server this is the quickest way to run the majority of the pgx test suite, and it needs nothing from the section above. Some tests will be skipped that require server configuration changes (e.g. those testing different authentication methods).

Create and setup a test database:

export PGDATABASE=pgx_test
createdb
psql -c 'create extension hstore;'
psql -c 'create extension ltree;'
psql -c 'create domain uint64 as numeric(20,0);'

Ensure a postgres user exists. This happens by default in normal PostgreSQL installs, but some installation methods such as Homebrew do not.

createuser -s postgres

Ensure your PGX_TEST_DATABASE environment variable points to the database you just created and run the tests.

export PGX_TEST_DATABASE="host=/private/tmp database=pgx_test"
go test ./...

This will run the vast majority of the tests, but some tests will be skipped (e.g. those testing different connection methods).

PgBouncer

There are tests specific for PgBouncer that will be executed if PGX_TEST_PGBOUNCER_CONN_STRING is set. The test PgBouncer must be version 1.21.0 or newer, use transaction pooling, and have max_prepared_statements set to a non-zero value. This ensures the tests cover PgBouncer's protocol-level named prepared statement support in addition to the pgx query modes that do not use named prepared statements.

Optional Tests

pgx supports multiple connection types and means of authentication. These tests are optional. They will only run if the appropriate environment variables are set. In addition, there may be tests specific to particular PostgreSQL versions, non-PostgreSQL servers (e.g. CockroachDB), or connection poolers (e.g. PgBouncer). go test ./... -v | grep SKIP to see if any tests are being skipped.