Skip to content

feat(engines): add PostgreSQL driver - #4

Merged
phuthuycoding merged 1 commit into
mainfrom
kf/postgres-driver
Oct 10, 2026
Merged

phuthuycoding merged 1 commit into
mainfrom
kf/postgres-driver

Conversation

@phuthuycoding

Copy link
Copy Markdown
Owner

Summary

  • New internal/driver/postgres package implementing driver.Driver — postgres:db databases clone between any two endpoints (remote→local, local→remote, remote→remote) with the same streaming, retried, pooled pipeline as mongo/mysql.
  • Whole-db clone: pg_dump -Fd writes a transient archive dir inside the local container → pg_restore -j --clean --if-exists --no-owner --no-privileges restores it (pg_restore -j cannot read from stdin, so the stage lives inside the container and is removed per attempt). Dump-side -j is skipped to avoid snapshot privileges on managed hosts.
  • -only postgres:db.schema.table: plain-format pg_dump -Fp -t in three phases — pre-data+data, selected tables' trigger functions via pg_get_functiondef, then post-data through an awk filter that drops FKs referencing unselected objects (reported as warnings).
  • Local container contract: postgres image, DBCLONE_POSTGRES_CONTAINER, POSTGRES_PASSWORD; compose.yaml, README.md, profiles.example.json updated.

Closes #3

Test plan

  • gofmt -l ., go vet ./..., go build ./... — clean
  • go test ./... — all packages green
  • 8 unit tests (fields/address, safe-name, stream flags, -t args, awk FK filter, Permanent, stage markers)
  • 6 integration tests on two postgres:17-alpine containers over a private network: preflight, whole-db clone (schemas, view, matview data, function, trigger, sequence setval, re-run clean), -only subset (dangling FK skipped+warned), -fresh under an open connection, remote→remote, auth fast-fail
  • Coverage 90.3% on internal/driver/postgres

pg_dump/pg_restore/psql inside the local postgres container: whole-db
clones stage a transient -Fd archive for pg_restore -j (which cannot read
stdin), -only subsets stream a filtered plain-format dump through psql.
Includes preflight contract, compose service, docs and unit+integration
tests.
@phuthuycoding
phuthuycoding merged commit d30437e into main Oct 10, 2026
1 check passed
@phuthuycoding
phuthuycoding deleted the kf/postgres-driver branch October 11, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

postgres-driver

1 participant