Skip to content

refactor(sponsor-panel): migrate from raw SQL to GORM#1183

Merged
Xe merged 11 commits intomainfrom
Xe/sponsor-panel-gorm
Mar 26, 2026
Merged

refactor(sponsor-panel): migrate from raw SQL to GORM#1183
Xe merged 11 commits intomainfrom
Xe/sponsor-panel-gorm

Conversation

@Xe
Copy link
Owner

@Xe Xe commented Mar 26, 2026

Summary

  • Replace all raw pgxpool + hand-written SQL in cmd/sponsor-panel with GORM, matching the pattern used by cmd/github-sponsor-webhook and internal/models
  • Add slog-gorm for structured database logging and gorm-prometheus for DB metrics
  • Rename User to PanelUser to avoid collision with internal/models.Account
  • Delete migrations.go — GORM AutoMigrate handles schema creation
  • Add cmd/sponsor-panel-drop-indexes one-shot tool to clean up old hand-created indexes before first GORM startup

Test plan

  • go build ./cmd/sponsor-panel/... compiles cleanly
  • go vet ./cmd/sponsor-panel/... passes
  • go test ./cmd/sponsor-panel/... passes
  • Run sponsor-panel-drop-indexes against dev database to clear old indexes
  • Start sponsor-panel and verify GORM AutoMigrate recreates indexes
  • Test GitHub OAuth login flow end-to-end
  • Test Patreon OAuth login flow end-to-end
  • Verify sponsor sync loop completes successfully
  • Verify Prometheus metrics at /metrics include GORM DB stats

Xe added 11 commits March 26, 2026 12:05
Replace raw pgxpool structs and SQL helper functions with GORM-tagged
models. Rename User to PanelUser to avoid collision with internal/models.
All DB helpers now take *gorm.DB instead of context + *pgxpool.Pool.
Add TableName() methods and PanelModels() for AutoMigrate.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
GORM AutoMigrate replaces hand-written CREATE TABLE statements
and ALTER TABLE migrations.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
Replace pgxpool.Pool with gorm.DB on Server struct. Use slog-gorm
for structured logging and gorm-prometheus for database metrics.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
Replace s.pool with s.db, update function signatures, rename User
to PanelUser, and cast user.ID to int for session compatibility.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
Replace s.pool with s.db, rename User to PanelUser, cast user.ID
to int for session storage.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
Replace s.pool with s.db for createLogoSubmission call.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
Replace pgxpool.Pool with gorm.DB in syncSponsors and startSyncLoop.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
One-shot tool to drop old hand-created indexes and constraints
so GORM AutoMigrate can recreate them with its own naming scheme.

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
Signed-off-by: Xe Iaso <me@xeiaso.net>
Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
@Xe Xe merged commit 9230411 into main Mar 26, 2026
3 checks passed
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