refactor: migrate from lib/pq to jackc/pgx (#10219)

This PR migrates the unmaintaiend `lib/pq` library to `jackc/pgx`, which is the de-facto standard lib in go for postgres connections these days.

Some implementation notes:

We register both `pgx` and `postgresschema` driver names (for backward comp). We can't register `postgres` as this one is still used by `lib/pq` imported by `go-chi/session`, which is in use when users go for the "postgres" session type in the "Session config.
It is questionable if anyone is really using the "postgres" driver option in the session config - but for consistency, it would be good to also migrate to `pgx` there, especially as the code lives within Forgejo under [go-chi/session](https://code.forgejo.org/go-chi/session).

`pgx` supports multi-host notation in the connection string. New tests have been added therefore.

`pgx` also allows for connection string parameters such as `?default_query_exec_mode=simple_protocol`. This should possibly allow running with `pgbouncer` "transaction" mode instead of "session", which could substantially enhance Postgres query handling.

## Checklist

### Tests

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I added test coverage for JavaScript changes...
  - [ ] in `web_src/js/*.test.js` if it can be unit tested.
  - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)).

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [x] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10219
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: pat-s <patrick.schratz@gmail.com>
Co-committed-by: pat-s <patrick.schratz@gmail.com>
This commit is contained in:
pat-s 2025-11-30 17:47:45 +01:00 committed by Mathieu Fenniak
parent 36ea60023a
commit c39a4368af
37 changed files with 472 additions and 334 deletions

View file

@ -9,13 +9,13 @@
ref: "refs/heads/master"
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
event: "push"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 1
started: 1683636528
stopped: 1683636626
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0
event_payload: |
{
@ -217,13 +217,13 @@
ref: "refs/heads/master"
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
event: "push"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 1
started: 1683636528
stopped: 1683636626
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0
event_payload: |
{
@ -424,13 +424,13 @@
ref: "refs/heads/master"
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
event: "push"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 1
started: 1683636528
stopped: 1683636626
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0
-
id: 794
@ -443,13 +443,13 @@
ref: "refs/heads/test"
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
event: "push"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 1
started: 1683636528
stopped: 1683636626
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0
-
id: 891
@ -462,13 +462,13 @@
ref: "refs/heads/branch2"
commit_sha: "985f0301dba5e7b34be866819cd15ad3d8f508ee"
event: "push"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 1 # success
started: 1683636528
stopped: 1683636626
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0
event_payload: '{"head_commit":{"id":"5f22f7d0d95d614d25a5b68592adb345a4b5c7fd"}}'
@ -485,13 +485,13 @@
ref: "refs/heads/main"
commit_sha: "97f29ee599c373c729132a5c46a046978311e0ee"
event: "push"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 1 # success
started: 1683636528
stopped: 1683636626
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0
-
@ -505,13 +505,13 @@
ref: "refs/heads/bugfix-1"
commit_sha: "35c5cddfc19397501ec8f4f7bb808a7c8f04445f"
event: "pull_request"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 2 # failure
started: 1683636528
stopped: 1683636626
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0
-
@ -526,10 +526,10 @@
commit_sha: "97f29ee599c373c729132a5c46a046978311e0ee"
event: "workflow_dispatch"
trigger_event: "workflow_dispatch"
is_fork_pull_request: 0
is_fork_pull_request: false
status: 6 # running
started: 1683636528
created: 1683636108
updated: 1683636626
need_approval: 0
need_approval: false
approved_by: 0

View file

@ -4,7 +4,7 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_2
attempt: 1
job_id: job_2
@ -18,7 +18,7 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_2
attempt: 1
job_id: job_2
@ -32,7 +32,7 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
name: job1 (1)
attempt: 1
job_id: job1
@ -46,7 +46,7 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
name: job1 (2)
attempt: 1
job_id: job1
@ -60,7 +60,7 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
name: job2
attempt: 1
job_id: job2
@ -75,7 +75,7 @@
repo_id: 1
owner_id: 1
commit_sha: 985f0301dba5e7b34be866819cd15ad3d8f508ee
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_2
attempt: 1
job_id: job_2
@ -89,7 +89,7 @@
repo_id: 1
owner_id: 1
commit_sha: 985f0301dba5e7b34be866819cd15ad3d8f508ee
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_2
attempt: 1
job_id: job_2
@ -104,7 +104,7 @@
repo_id: 1
owner_id: 2
commit_sha: 985f0301dba5e7b34be866819cd15ad3d8f508ee
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_2
attempt: 2
job_id: job_2
@ -119,7 +119,7 @@
repo_id: 1
owner_id: 3
commit_sha: 985f0301dba5e7b34be866819cd15ad3d8f508ee
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_2
attempt: 1
job_id: job_2
@ -134,7 +134,7 @@
repo_id: 4
owner_id: 1
commit_sha: 985f0301dba5e7b34be866819cd15ad3d8f508ee
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_2
attempt: 0
job_id: job_2
@ -149,7 +149,7 @@
repo_id: 1
owner_id: 3
commit_sha: ea09cba7099f7e3bea80dee1a42f0b5d5e127f2e
is_fork_pull_request: 0
is_fork_pull_request: false
name: job_3
attempt: 1
job_id: job_3

View file

@ -3,7 +3,7 @@
token: xeiWBL5kuTYxGPynHCqQdoeYmJAeG3IzGXCYTrDX
owner_id: 0
repo_id: 0
is_active: 1
is_active: true
created: 1695617748
updated: 1695617748
@ -12,7 +12,7 @@
token: vohJB9QcZuSv1gAXESTk2uqpSjHhsKT9j4zYF84x
owner_id: 1
repo_id: 0
is_active: 0
is_active: false
created: 1695617749
updated: 1695617749
@ -21,7 +21,7 @@
token: gjItAeJ3CA74hNPmPPo0Zco8I1eMaNcP1jVifjOE
owner_id: 1
repo_id: 0
is_active: 1
is_active: true
created: 1695617750
updated: 1695617750
@ -30,6 +30,6 @@
token: NOjLubxzFxPGhPXflZknys0gjVvQNhomFbAYuhbH
owner_id: 0
repo_id: 1
is_active: 1
is_active: true
created: 1695617751
updated: 1695617751

View file

@ -8,15 +8,15 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: 6d8ef48297195edcc8e22c70b3020eaa06c52976db67d39b4260c64a69a2cc1508825121b7b8394e48e00b1bf8718b2aaaaa
token_salt: eeeeeeee
token_last_eight: eeeeeeee
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false
-
id: 47
job_id: 192
@ -28,15 +28,15 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: 6d8ef48297195edcc8e22c70b3020eaa06c52976db67d39b4260c64a69a2cc1508825121b7b8394e48e00b1bf8718b2a867e
token_salt: jVuKnSPGgy
token_last_eight: eeb1a71a
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false
-
id: 48
job_id: 193
@ -48,15 +48,15 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: ffffcfffffffbffffffffffffffffefffffffafffffffffffffffffffffffffffffdffffffffffffffffffffffffffffffff
token_salt: ffffffffff
token_last_eight: ffffffff
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false
-
id: 49
job_id: 194
@ -68,15 +68,15 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784220
token_salt: ffffffffff
token_last_eight: ffffffff
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false
-
id: 50
job_id: 195
@ -88,15 +88,15 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784221
token_salt: ffffffffff
token_last_eight: ffffffff
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false
-
id: 51
job_id: 196
@ -108,15 +108,15 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784222
token_salt: ffffffffff
token_last_eight: ffffffff
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false
-
id: 52
job_id: 192
@ -128,15 +128,15 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784223
token_salt: ffffffffff
token_last_eight: ffffffff
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false
-
id: 53
job_id: 192
@ -148,12 +148,12 @@
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
is_fork_pull_request: 0
is_fork_pull_request: false
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784224
token_salt: ffffffffff
token_last_eight: ffffffff
log_filename: artifact-test2/2f/47.log
log_in_storage: 1
log_in_storage: true
log_length: 707
log_size: 90179
log_expired: 0
log_expired: false

View file

@ -268,7 +268,7 @@
poster_id: 1
issue_id: 1 # in repo_id 1
label_id: 1
content: 1 # add label
content: "1" # add label
created_unix: 946685520
-
@ -277,7 +277,7 @@
poster_id: 1
issue_id: 1
label_id: 2
content: 1 # add label
content: "1" # add label
created_unix: 946685620
-
@ -286,7 +286,7 @@
poster_id: 2
issue_id: 1 # in repo_id 1
label_id: 1
content: 0 # remove label
content: "0" # remove label
created_unix: 946685720
-
@ -295,7 +295,7 @@
poster_id: 1
issue_id: 1 # in repo_id 1
label_id: 1
content: 1 # add label
content: "1" # add label
created_unix: 946685720
-
@ -304,7 +304,7 @@
poster_id: 1
issue_id: 1 # in repo_id 1
label_id: 2
content: 0 # remove label
content: "0" # remove label
created_unix: 946685720
-
@ -313,7 +313,7 @@
poster_id: 2
issue_id: 1 # in repo_id 1
label_id: 2
content: 1 # add label
content: "1" # add label
created_unix: 946685820
-
@ -322,7 +322,7 @@
poster_id: 1
issue_id: 1 # in repo_id 1
label_id: 1
content: 0 # remove label
content: "0" # remove label
created_unix: 946685920
-
@ -331,7 +331,7 @@
poster_id: 1
issue_id: 1 # in repo_id 1
label_id: 2
content: 0 # remove label
content: "0" # remove label
created_unix: 946685920
- id: 2040

View file

@ -249,5 +249,5 @@
authorize: 3
num_repos: 0
num_members: 0
includes_all_repositories: 0
can_create_org_repo: 0
includes_all_repositories: false
can_create_org_repo: false