feat(store): purge old notifications, invitations, tokens and incidents
Refs #63 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
97229b91d1
commit
057e41d5b6
3 files changed
+80
No files matched your search
@@ -0,0 +1,61 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: housekeeping.sql
|
||||
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const purgeExpiredTokens = `-- name: PurgeExpiredTokens :execrows
|
||||
DELETE FROM api_tokens WHERE expires_at < $1
|
||||
`
|
||||
|
||||
func (q *Queries) PurgeExpiredTokens(ctx context.Context, expiresAt *time.Time) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, purgeExpiredTokens, expiresAt)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const purgeIncidents = `-- name: PurgeIncidents :execrows
|
||||
DELETE FROM incidents WHERE resolved_at < $1
|
||||
`
|
||||
|
||||
// Incidents resolved before the oldest data still charted.
|
||||
func (q *Queries) PurgeIncidents(ctx context.Context, resolvedAt *time.Time) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, purgeIncidents, resolvedAt)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const purgeInvitations = `-- name: PurgeInvitations :execrows
|
||||
DELETE FROM invitations WHERE expires_at < $1 OR accepted_at < $1
|
||||
`
|
||||
|
||||
func (q *Queries) PurgeInvitations(ctx context.Context, expiresAt time.Time) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, purgeInvitations, expiresAt)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const purgeNotifications = `-- name: PurgeNotifications :execrows
|
||||
DELETE FROM notifications WHERE status IN ('sent', 'failed') AND created_at < $1
|
||||
`
|
||||
|
||||
// Delivered and given-up notifications; pending ones are still being worked.
|
||||
func (q *Queries) PurgeNotifications(ctx context.Context, createdAt time.Time) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, purgeNotifications, createdAt)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
Reference in new issue
Block a user