refactor(sponsor-panel): migrate from raw SQL to GORM#1183
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pgxpool+ hand-written SQL incmd/sponsor-panelwith GORM, matching the pattern used bycmd/github-sponsor-webhookandinternal/modelsslog-gormfor structured database logging andgorm-prometheusfor DB metricsUsertoPanelUserto avoid collision withinternal/models.Accountmigrations.go— GORM AutoMigrate handles schema creationcmd/sponsor-panel-drop-indexesone-shot tool to clean up old hand-created indexes before first GORM startupTest plan
go build ./cmd/sponsor-panel/...compiles cleanlygo vet ./cmd/sponsor-panel/...passesgo test ./cmd/sponsor-panel/...passessponsor-panel-drop-indexesagainst dev database to clear old indexessponsor-paneland verify GORM AutoMigrate recreates indexes/metricsinclude GORM DB stats