Skip to content

fix(ivory): honor ordinary per-database SQL targets - #89

Open
Hanabi9248 wants to merge 1 commit into
IvorySQL:masterfrom
Hanabi9248:codex/ivory-per-database-target-oct26
Open

Hanabi9248 wants to merge 1 commit into
IvorySQL:masterfrom
Hanabi9248:codex/ivory-per-database-target-oct26

Conversation

@Hanabi9248

@Hanabi9248 Hanabi9248 commented Oct 26, 2026 •

Copy link
Copy Markdown

PostGIS and pgAudit call ExecInAllDatabases to install their extensions in every connectable database. The ordinary loop enumerates those databases and sets PGDATABASE, but its target command also specifies psql -d postgres. That explicit database argument overrides the per-iteration environment value, so the target SQL is repeatedly directed to the maintenance database.

Remove the overriding argument from the ordinary target loop. Keep the catalog query and Executor.Exec explicitly connected to postgres. Keep PGDATABASE for literal database names, including names containing spaces or looking like connection strings. The special monitoring/PgBouncer script remains byte-for-byte unchanged: the existing pgMonitor caller supplies \c postgres, which is a different input contract. Variable forwarding and other executor behavior are outside this change.

Validation on base 0240ce2a2c451164c666fb769b6e837ee244175f:

  • Complete production exec.go compiled in Go named-file mode with the added regression. The real generated Bash script runs with a clearly scoped psql command fixture that supplies catalog output and observes arguments, stdin and PGDATABASE. It does not emulate libpq or a database.
  • Baseline: the ordinary loop fails at the command boundary because it overrides PGDATABASE; both legacy caller controls pass.
  • Candidate: the ordinary Bash regression and two legacy command-capture controls pass. The ordinary case checks postgres, template1, a name with spaces, and a conninfo-looking name. The two compatibility controls capture the actual pgMonitor connect-meta-command and PgBouncer catalog caller, without claiming those scripts were executed against psql.
  • go vet exec.go exec_database_target_test.go passes. Two existing ordinary-script expectations are updated.
  • Go 1.27.1 on Windows with Git Bash; CPU 1, 768 MiB aggregate memory, 16 processes, private temporary files and single-threaded BLAS; peak job memory 218,161,152 bytes. No dependencies installed.
  • Full ./internal/ivory testing could not start because pinned dependencies are absent from the existing offline cache (GOPROXY=off). Full package/repository tests, ShellCheck, actual psql/libpq, IvorySQL image compatibility, extensions and Kubernetes integration were not run.

An initial two-loop candidate was rejected during caller review and is not included. An initial Windows test attempt lacked a usable /dev/stdin pipe; the fixture now provides the same SQL through a real temporary input file. Final baseline and candidate above were both rerun after narrowing the production change.

The client option/environment distinction is documented in psql connection parameters and agrees with the current IvorySQL client source.

Checklist

  • Explanation and code comments added.
  • Automated regression added.
  • All related environments tested (limits listed above).

Type of changes

  • Bug fix
  • Testing enhancement

Summary by CodeRabbit

  • Bug Fixes
    • Queries run against selected databases now use the selected database connection setting instead of explicitly overriding the target to postgres.
    • Catalog and monitoring queries continue to target postgres, preserving their existing behavior.

Keep the maintenance catalog connection explicit while allowing PGDATABASE
in the ordinary target loop to select each enumerated database. Preserve
the legacy monitoring script and cover its real caller command contract.

Signed-off-by: Hanabi <317387557+Hanabi9248@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e66070a9-9b60-4e53-8e4b-5cd1e48b938d
Commits

Reviewing files that changed from the base of the PR and between 0240ce2 and b5b4eab.

Files selected for processing: 3
  • internal/ivory/exec.go
  • internal/ivory/exec_database_target_test.go
  • internal/ivory/exec_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The standard per-database target query now uses PGDATABASE instead of -d postgres. Catalog queries and the separate monitoring-script path retain their explicit postgres behavior. Tests cover these command boundaries.

Changes: Database Target Selection

Layer / File(s) Summary
Target command and regression coverage
internal/ivory/exec.go, internal/ivory/exec_database_target_test.go, internal/ivory/exec_test.go
The standard target-query command uses PGDATABASE without a database override argument. New and updated tests check the target and catalog command arguments, and verify legacy monitoring command compatibility.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: balinorliang

Merge Risk: Minimal · up to b5b4e

No concrete merge-blocking issue remains. Named database targets now use PGDATABASE; catalog and monitoring behavior remains unchanged. Full integration validation remains outstanding.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main fix: ordinary per-database SQL targets now honor their database selection.
Description check Passed The description explains the current and new behavior, identifies the bug, documents the scope, lists automated validation, records test limitations, and categorizes the change as a bug fix and testin…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the current and new behavior, identifies the bug, documents the scope, lists automated validation, records test limitations, and categorizes the change as a bug fix and testing enhancement.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant