feat(db): add PostgreSQL backend#755
Merged
Merged
Conversation
Add PostgreSQL as a third SQL backend alongside SQLite and MySQL: - config: PostgreSQL backend type, connection settings, validation and DSN construction (sslmode, port range, special-character quoting). - driver wiring: open the pgx-backed gorm driver, apply connection-pool tuning, and reuse the main connection for blob storage (no separate objects database as SQLite uses). - file store: store file-object blobs in PostgreSQL Large Objects, keyed by lo_oid; SQLite continues to use the Content BLOB column. - migrations: dedicated file_object_migrations tracking table with a rename shim so existing SQLite installs preserve their history, plus a functional LOWER(tag) index and lo_oid column for file_object blobs. - getUserByID pre-validates UUIDs so PostgreSQL's uuid column returns ErrNotFound on malformed input instead of a driver error. - tests: parametrize the SQL suite to run against PostgreSQL when GARM_TEST_POSTGRES_DSN is set, and add a PostgreSQL CI job.
742b264 to
1bad028
Compare
The self-hosted ubuntu-noble-garm runners have no Docker, so the go-tests-postgres job failed during job setup with 'docker: command not found' when initializing the postgres service container. Install and run PostgreSQL from the distro package instead, matching the apt-based dependency pattern used by the other jobs on these runners.
Member
|
I added docker to the CI runners. You should be able to use the |
…ontainer" This reverts commit 5370c6f.
gabriel-samfira
approved these changes
Jun 3, 2026
Member
|
Thank you! |
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.
Closes #753
What
Add PostgreSQL as a third SQL backend alongside SQLite and MySQL, selectable via
backend = "postgresql":construction (sslmode, port-range checks, special-character quoting).
tuning (max open/idle, lifetimes), and reuse the main connection for blob
storage (PostgreSQL needs no separate objects database like SQLite uses).
(keyed by
lo_oid), not abyteacolumn. Large Objects support chunked,seekable streaming via the
loAPI, so blobs are read/written incrementallyand never fully held in memory — required because GARM's file-object interface
is streaming (
CreateFileObject(..., io.Reader)/OpenFileObjectContent(...) io.ReadCloser), and abyteavalue would have tobe materialized in full. Writes
io.Copythe reader into the Large Object(hashing inline); reads return a
ReadCloseroverlo.Read. SQLite continuesto use the
ContentBLOB column.file_object_migrationstracking table with arename shim so existing SQLite installs preserve their file-object migration
history, plus a functional
LOWER(tag)index and thelo_oidcolumn forfile_objectblobs.getUserByIDpre-validates UUIDs so PostgreSQL'suuidcolumn returns
ErrNotFoundon malformed input instead of a driver error.GARM_TEST_POSTGRES_DSNis set, and add a PostgreSQL job to the test workflow.Notes for reviewers
pgx,gorm.io/driver/postgresand transitive deps). The hand-written change is ~970 lines; the rest is
vendor/.LOWER()foldsASCII only, PostgreSQL's is locale-aware (folds Unicode). For GARM's
effectively-ASCII identifiers this is a non-issue, but noting it explicitly.
Testing
suites against
postgres:16(Docker,fsync=off) using the same image,credentials, and DSN as the CI job —
database/sqlandconfigpass with-race -tags testing -count=1.ok github.com/cloudbase/garm/database/sql (PostgreSQL backend)
ok github.com/cloudbase/garm/config
backends are covered.
make lint(golangci-lint v2.10.1) is clean — 0 issues.make go-testagainst apostgres:16service viaGARM_TEST_POSTGRES_DSN, exercisingmigrations/AutoMigrate and the Large Object file store on a real PostgreSQL.
cbartz/garm— created credentials, repo, and a scale set, and confirmedrunners register with GitHub and execute jobs.
Future work
The nightly integration suite (
test/integration, scheduled inintegration-tests.yml) still runs only against SQLite — its config hardcodesbackend = "sqlite3". The PostgreSQL path was validated manually end-to-end (seeTesting); automating that in the nightly suite (add a PG service + template the
[database]config) would be a natural follow-up.