Skip to content

fix: abort idempotent install on non-SQL errors instead of installing - #3196

Open
twiesing wants to merge 1 commit into
knadh:masterfrom
twiesing:fix/idempotent-install-error-check
Open

fix: abort idempotent install on non-SQL errors instead of installing#3196
twiesing wants to merge 1 commit into
knadh:masterfrom
twiesing:fix/idempotent-install-error-check

Conversation

@twiesing

Copy link
Copy Markdown
Contributor

Fixes #3195.

The --install --idempotent check only aborted on *pq.Error values with a code other than 42P01. Errors of any other type — which is what connection-level failures surface as (e.g. *net.OpError after database/sql exhausts its ErrBadConn retries, exactly the situation while a DB container is still coming up) — failed the type assertion, skipped the Fatalf, and fell through to installSchema(). Since schema.sql drops every table before recreating it, a transient connectivity blip during the check could wipe a populated database (see the issue for a real-world incident).

This change reuses isTableNotExistErr() from cmd/upgrade.go so that only the positive "settings table does not exist" (42P01) signal triggers installation; every other error — SQL or otherwise — aborts before anything destructive runs.

Behavior change: previously non-fatal check failures (network errors, driver.ErrBadConn, context cancellation) now abort with an error. That is intentional — none of them proves the database is empty, and in a containerized setup the process simply restarts and re-checks.

Verified with go build ./cmd, go vet ./cmd and gofmt.

The --install --idempotent check only aborted on *pq.Error with a code
other than 42P01. Connection-level failures (e.g. net.OpError while a
DB container is still coming up) failed the type assertion and fell
through to the destructive schema install, wiping a populated database.
Use isTableNotExistErr() so that only a missing settings table (42P01)
triggers installation and every other error aborts.

Fixes knadh#3195
@twiesing
twiesing force-pushed the fix/idempotent-install-error-check branch from 44be40b to 7b11878 Compare August 18, 2026 07:48
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.

--install --idempotent: non-SQL errors during the idempotency check fall through to a destructive install

1 participant