Fix duplicate leaderboard entries, add /version command, fix jail DNS
- db/db.go: Add write-time username sync in AddLog to prevent duplicate leaderboard entries when users change display names. Revert correlated subqueries back to GROUP BY user_id, username (simpler approach). - db/db.go: Early return in onMessageCreate if bot already reacted (prevents duplicate emoji reactions on Discord reconnection). - bot/bot.go: Add /version slash command with build version injection. - main.go: Add version variable with ldflags support. - Makefile: Add dns-fix, test, vet, build-native, pg-*, boot targets. Prepend test+vet to deploy pipeline. Add version ldflags to build. - db/migrations/002_fix_usernames.sql: One-time SQL to backfill old usernames. - scripts/fix-jail-dns.sh: Script to update jail resolv.conf from 8.8.8.8 to reachable nameservers (1.1.1.1, 9.9.9.9, 172.16.0.1). Signed-off-by: Blake Ridgway <blake@blakeridgway.com>
This commit is contained in:
9
db/db.go
9
db/db.go
@@ -148,6 +148,15 @@ func (d *DB) AddLog(ctx context.Context, guildID, userID, username, messageID, c
|
||||
return false, fmt.Errorf("insert log: %w", err)
|
||||
}
|
||||
rows, _ := res.RowsAffected()
|
||||
if rows > 0 {
|
||||
// Sync the display name across all existing logs for this user.
|
||||
// This prevents duplicate leaderboard entries when a user changes
|
||||
// their Discord display name.
|
||||
_, _ = d.conn.ExecContext(ctx, `
|
||||
UPDATE distance_logs SET username = $1
|
||||
WHERE guild_id = $2 AND user_id = $3 AND username != $1
|
||||
`, username, guildID, userID)
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
|
||||
|
||||
22
db/migrations/002_fix_usernames.sql
Normal file
22
db/migrations/002_fix_usernames.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- One-time migration: backfill old username entries when users change display names.
|
||||
-- The write-time UPDATE in db.go AddLog() handles future changes automatically.
|
||||
-- Run once after deploying: psql -d YOUR_DATABASE_URL -f db/migrations/002_fix_usernames.sql
|
||||
|
||||
UPDATE distance_logs d
|
||||
SET username = (
|
||||
SELECT username
|
||||
FROM distance_logs sub
|
||||
WHERE sub.user_id = d.user_id
|
||||
AND sub.guild_id = d.guild_id
|
||||
ORDER BY logged_at DESC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE username <> (
|
||||
SELECT username
|
||||
FROM distance_logs sub
|
||||
WHERE sub.user_id = d.user_id
|
||||
AND sub.guild_id = d.guild_id
|
||||
ORDER BY logged_at DESC
|
||||
LIMIT 1
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user