DeleteExpiredExportArchives deletes export archives older than the specified retention period. Returns the number of archives deleted.
(ctx context.Context, workspaceID string, retentionPeriod time.Duration)
| 94 | // DeleteExpiredExportArchives deletes export archives older than the specified retention period. |
| 95 | // Returns the number of archives deleted. |
| 96 | func (s *Store) DeleteExpiredExportArchives(ctx context.Context, workspaceID string, retentionPeriod time.Duration) (int64, error) { |
| 97 | cutoffTime := time.Now().Add(-retentionPeriod) |
| 98 | |
| 99 | q := qb.Q().Space("DELETE FROM export_archive WHERE workspace = ?", workspaceID).And("created_at < ?", cutoffTime) |
| 100 | query, args, err := q.ToSQL() |
| 101 | if err != nil { |
| 102 | return 0, errors.Wrapf(err, "failed to build sql") |
| 103 | } |
| 104 | |
| 105 | result, err := s.GetDB().ExecContext(ctx, query, args...) |
| 106 | if err != nil { |
| 107 | return 0, err |
| 108 | } |
| 109 | |
| 110 | rowsAffected, err := result.RowsAffected() |
| 111 | if err != nil { |
| 112 | return 0, err |
| 113 | } |
| 114 | |
| 115 | return rowsAffected, nil |
| 116 | } |