Skip to content

refactor(Setup/PostgreSQL): more robust credential handling and code organization#58391

Open
joshtrichards wants to merge 10 commits intomasterfrom
jtr/refactor-setup-pgsql
Open

refactor(Setup/PostgreSQL): more robust credential handling and code organization#58391
joshtrichards wants to merge 10 commits intomasterfrom
jtr/refactor-setup-pgsql

Conversation

@joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Feb 17, 2026

Summary

Before:

  • Key properties were overused (e.g. $this->dbUser / $this->dbPassword) that made logic harder to follow, troubleshoot, or change
  • Different scenarios all followed the same code path unnecessarily (i.e. automatic credential creation versus manually pre-provisioned by admin)
  • Didn't use any helpers making it harder to read/troubleshoot

After:

  • Code is easier to follow.
  • Clearer separation of concerns
  • Elimination of hidden state dependencies.

Easiest to review probably by commit-by-commit

Specific improvements:

  1. Credential Management
    • Admin credentials now saved in local variables before mutation
    • Credentials generated entirely inside createDBUser() and only assigned to $this-> after success
    • userExists() now accepts explicit "dbUser" parameter
  2. Code Organization
    • Separates automatic vs. manual setup paths (new performAutomaticSetup() introduced + less conditional logic depth)
    • Extracted key bits of existing logic into new helpers: checkCanCreateRoles(), verifyDatabaseConnection(), grantCreateOnPublicSchema()
    • Single $connection object/variable; less confusion between connection scenarios and more explicit lifecycle management
  3. Observability
    • Better error context (user, database, exception details)
    • Some additional logging scenarios and clarity (e.g. when alternate username chosen)
    • Added 'app' => 'pgsql.setup' to all log contexts

TODO

  • ...

Checklist

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
And consolidate credential generation logic in a single place

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
…le admin credentials

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards force-pushed the jtr/refactor-setup-pgsql branch from a5ed07d to f9f27ce Compare February 18, 2026 15:25
@joshtrichards joshtrichards added 3. to review Waiting for reviews ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) labels Feb 18, 2026
@joshtrichards joshtrichards marked this pull request as ready for review February 18, 2026 18:00
@joshtrichards joshtrichards requested a review from a team as a code owner February 18, 2026 18:00
@joshtrichards joshtrichards requested review from Altahrim, ArtificialOwl, come-nc and icewind1991 and removed request for a team February 18, 2026 18:00
@joshtrichards joshtrichards added this to the Nextcloud 34 milestone Feb 18, 2026
@joshtrichards joshtrichards changed the title refactor(setup/pgsql): improve db setup credential handling and code organization refactor(Setup/PostgreSQL): more robust credential handling and code organization Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews feature: database Database related DB feature: install and update ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments