mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-14 00:16:38 +00:00
fix(db): add FK constraints, indexes, transaction fixes, and hook_executions tenant isolation (migrations 082-083) (#1246)
Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
This commit is contained in:
1 parent
c31dd21934
commit
756c4dce71
12 files changed
+397
-27
No files matched your search
@@ -314,14 +314,16 @@ func (s *SQLiteTracingStore) GetCostSummary(ctx context.Context, opts store.Cost
|
||||
}
|
||||
|
||||
// DeleteTracesOlderThan deletes traces and their spans older than cutoff.
|
||||
// SQLite's spans.trace_id has no FK reference to traces(id), so spans must be
|
||||
// deleted explicitly before the parent traces to avoid leaving orphaned span rows.
|
||||
// Returns total traces deleted.
|
||||
func (s *SQLiteTracingStore) DeleteTracesOlderThan(ctx context.Context, cutoff time.Time) (int64, error) {
|
||||
// Delete spans belonging to old traces.
|
||||
// Delete spans first — SQLite has no CASCADE on spans.trace_id.
|
||||
_, err := s.db.ExecContext(ctx,
|
||||
`DELETE FROM spans WHERE trace_id IN (SELECT id FROM traces WHERE created_at < ?)`, cutoff)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("delete old spans: %w", err)
|
||||
}
|
||||
|
||||
res, err := s.db.ExecContext(ctx, `DELETE FROM traces WHERE created_at < ?`, cutoff)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("delete old traces: %w", err)
|
||||
|
||||
Reference in new issue
Block a user