Skip to content

refactor(auth): split store_postgres.go into group, session and admin files - #1546

Merged
cristim merged 5 commits into
mainfrom
refactor/auth-store-postgres-split
Oct 27, 2026
Merged

cristim merged 5 commits into
mainfrom
refactor/auth-store-postgres-split

Conversation

@cristim

@cristim cristim commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Closes #86.

internal/auth/store_postgres.go was 835 lines, over the repo's 500-line ceiling. This PR splits it with a pure move inside package auth. No function body, signature, name or comment changes; only the files the declarations live in, and their import blocks.

file now holds lines
store_postgres.go NewPostgresStore, user CRUD, nullTimePtr, scanUser, Ping 297
store_postgres_groups.go (new) GetGroup, CreateGroup, UpdateGroup, DeleteGroup, ListGroups, scanGroup 211
store_postgres_sessions.go (new) CreateSession, GetSession, DeleteSession, DeleteUserSessions, CleanupExpiredSessions 111
store_postgres_admin.go (new) isDuplicateKeyError, isEmailDuplicateError, isLastAdminConstraintViolation, AdminExists, CountGroupMembers, withAdminInvariantLock, CreateAdminIfNone 249

There are five commits, one move each, each ≤400 added+deleted lines: 224, 186, 213, 165 and 321.

Verification:

  • Same declarations: a script extracted every top-level func/type/var/const with its doc comment, from main's store_postgres.go and from the four files at HEAD. Both sides have 34 declarations, and the sorted sets are identical.
  • Only moves: the removed and added lines match as multisets. The only added lines with no matching removal are package auth, import blocks and blank lines.
  • Build and tests: go build ./... and go vet ./internal/auth/ pass after every commit. go test -race ./internal/auth/ passes, and so does go test -race -tags integration ./internal/auth/ on real Postgres (testcontainers).
  • Pre-commit: passed for each commit, with hadolint, actionlint, zizmor and cfn-lint skipped, because their environments can't be built locally. CI runs them.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • PostgreSQL-backed administrator, group, and session management continues to be supported, with no user-visible behavior changes.

cristim and others added 5 commits October 27, 2026 21:14
…_postgres_groups.go

Pure move inside package auth; function bodies are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_postgres_groups.go

Pure move inside package auth; function bodies are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ssions.go

Pure move inside package auth; function bodies are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_postgres_admin.go

Pure move inside package auth; function bodies are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nto store_postgres_admin.go

Pure move inside package auth; function bodies are unchanged.

Closes #86

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cristim cristim added impact/internal Team-internal only type/chore Maintenance / non-user-visible triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline effort/m Days labels Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 1d10f08 and 7b9e1c5.

Files selected for processing: 4
  • internal/auth/store_postgres.go
  • internal/auth/store_postgres_admin.go
  • internal/auth/store_postgres_groups.go
  • internal/auth/store_postgres_sessions.go
Files with no reviewable changes: 1
  • internal/auth/store_postgres.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 PostgreSQL store moves admin, group, and session operations out of store_postgres.go into domain-specific files. The operations retain their database queries, transaction handling, row scanning, and error handling.

Changes: PostgreSQL Store Split

Layer / File(s) Summary
Separate domain operations from the core store file
internal/auth/store_postgres.go, internal/auth/store_postgres_admin.go, internal/auth/store_postgres_groups.go, internal/auth/store_postgres_sessions.go
The core store file removes admin, group, and session methods and related code. The operations are defined in the corresponding domain-specific files.
Admin membership and invariant operations
internal/auth/store_postgres_admin.go
Admin helpers check active membership, count group members, detect specified database constraint violations, and create the first admin through a conditional insert within an advisory-lock transaction.
Group persistence and row scanning
internal/auth/store_postgres.go, internal/auth/store_postgres_groups.go
Group retrieval, creation, updates, deletion, and listing use PostgreSQL queries. The group scanner handles permissions and nullable creator IDs.
Session persistence and cleanup
internal/auth/store_postgres_sessions.go
Session methods create, retrieve, and delete sessions, delete a user’s sessions, and clean up expired sessions.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Suggested reviewers: iamjsd

Merge Risk: Minimal · up to 7b9e1

The store split preserves the inspected implementations and is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue [#86] requires all affected files to stay below 500 lines, movement-only changes, and passing go build ./..., go vet ./..., and go test ./internal/auth/... -count=1. The PR reports file si… Provide results for go vet ./... and go test ./internal/auth/... -count=1 at the reviewed head.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: splitting store_postgres.go into separate group, session, and admin files.
Out of Scope Changes check Passed The changes remain within issue [#86]. They move PostgreSQL store declarations into same-package group, session, and admin files. The diff evidence shows import and blank-line updates only in addition…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Full details: Out of Scope Changes check

Explanation

The changes remain within issue [#86]. They move PostgreSQL store declarations into same-package group, session, and admin files. The diff evidence shows import and blank-line updates only in addition to the moves. No unrelated behavior, API, or call-site changes are identified.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 3 files.

Full details: Linked Issues check

Explanation

Issue [#86] requires all affected files to stay below 500 lines, movement-only changes, and passing go build ./..., go vet ./..., and go test ./internal/auth/... -count=1. The PR reports file sizes of 297, 211, 111, and 249 lines. The diff moves declarations between same-package files and changes only imports and blank lines. The PR reports the build and auth tests, but it reports go vet ./internal/auth/ and race-test variants instead of the required go vet ./... and exact test command. The available evidence does not establish those two required checks.

Resolution

Provide results for go vet ./... and go test ./internal/auth/... -count=1 at the reviewed head.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • 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.

@cristim

cristim commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Independent review 2 (claude-fleet, cold): APPROVE 7b9e1c5

Scope: internal/auth/store_postgres.go split into store_postgres_admin.go, store_postgres_groups.go and store_postgres_sessions.go. 4 files, +571/-538, base 1d10f08. Commit sizes are 224, 186, 213, 165 and 321 changed lines, all 400 or fewer.

Findings: none.

Pure-move proof:

  • I wrote a scratch go/ast dumper that prints every top-level declaration in the non-test files of package auth: funcs, methods with their receiver type, types, vars and consts. Each is printed with go/printer in a fixed configuration, together with its doc comment, and keyed by name.
  • Base and head each have 414 declarations, and the two dumps are byte-identical. No declaration was added, removed, renamed or changed, and no doc comment moved off its declaration.
  • The package's import set is identical, as a sorted union across files.
  • The net +33 lines are only per-file overhead: the three new files' package clauses and import blocks, plus the // === section banners moved with their code. Each new file imports only packages its own declarations use, and the build confirms that.

Verified (light, under the heavy lock):

  • go build ./internal/auth: ok.
  • go vet ./internal/auth, with and without -tags integration: ok.
  • go test -count=1 ./internal/auth: ok.
  • git merge-tree --write-tree origin/main 7b9e1c5: clean (30315378).

Reviewed by an independent agent with no author context (second reviewer). Review only: nothing was pushed, and the GitHub review state is unchanged.

@cristim

cristim commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

VERDICT: APPROVE 7b9e1c5
Findings: none. The "pure move" claim holds.

  • Declarations: I wrote my own go/ast extractor (each top-level non-import decl plus its doc comment, as raw source bytes, SHA-256). origin/main:store_postgres.go and the 4 head files each have 34 decls, every hash identical. No duplicates, none missing.
  • Unattached section-banner comments (USER/GROUP/SESSION/HELPER) are preserved byte for byte. GROUP and SESSION moved with their code into groups.go and sessions.go.
  • Other files: git diff --stat origin/main...7b9e1c5c touches only internal/auth/store_postgres{,_groups,_sessions,_admin}.go (+571/-538). The extra 33 added lines are the package clauses and import blocks.
  • Imports: every file builds and vets at every commit, and Go rejects unused imports at compile time. pgconn is imported as github.com/jackc/pgx/v5/pgconn (store_postgres.go, store_postgres_admin.go). gofmt -l is clean.
  • Order and init: internal/auth has no func init. The only package-level vars are var _ StoreInterface and two constant consts, so declaration order does not matter.
  • Commit sizes (added+deleted): 434b4ea=224, a2cd825=186, 9ce6e19=213, 4ccceb3=165, 7b9e1c5=321. All are ≤400.
  • Per-commit build: I extracted each SHA with git archive into a fresh dir and ran go build and go vet ./internal/auth/ under lockf. All 5 commits pass.
  • Tests: go test -race -count=1 ./internal/auth/ at the head passes (ok, 7.3s).
  • Note: file sizes at the head are 297/249/211/111 lines, all under the 500-line rule.

@cristim

cristim commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Local verification at 7b9e1c5c4788e34abe04b310aaac33945ff3d510 merged onto current main (1d10f086; merge-tree 30315378; macOS):

  • go build ./..., go vet -tags integration ./... and go test -race -short ./... pass (full suite).
  • go test -tags integration passes on real Postgres (testcontainers) for the touched packages: ./internal/auth
  • Nothing was applied to any cloud.

@cristim
cristim merged commit 7b86e38 into main Oct 27, 2026
41 checks passed
@cristim
cristim deleted the refactor/auth-store-postgres-split branch October 27, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(auth): split store_postgres.go below the 500-line ceiling (856 lines)

1 participant