summaryrefslogtreecommitdiff
path: root/internal/store/buckets.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/store/buckets.go')
-rw-r--r--internal/store/buckets.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/store/buckets.go b/internal/store/buckets.go
index 8bbcca9..1e3ce9a 100644
--- a/internal/store/buckets.go
+++ b/internal/store/buckets.go
@@ -89,6 +89,51 @@ func (s *Store) RemoveBucketItem(taskID string) error {
return checkRowsAffected(result)
}
+// GetBucketItems returns every task in a bucket's pool (dormant and active
+// both), active first, then by priority -- backs the bucket-management view.
+func (s *Store) GetBucketItems(bucketID string) ([]models.Task, error) {
+ rows, err := s.db.Query(`
+ SELECT id, content, description, project_name, project_id, due_date, priority, completed, labels, created_at,
+ recurrence_freq, recurrence_interval, recurrence_weekdays, recurrence_series_id, next_occurrence_override, estimated_minutes,
+ chain_id, chain_position, chain_unlocked,
+ bucket_id, bucket_state, bucket_last_active_at
+ FROM native_tasks
+ WHERE bucket_id = ?
+ ORDER BY (bucket_state = 'active') DESC, priority DESC
+ `, bucketID)
+ if err != nil {
+ return nil, err
+ }
+ defer func() { _ = rows.Close() }()
+ return scanNativeTasks(rows)
+}
+
+// DeleteBucket removes a bucket and returns every member task to being a
+// plain, unbucketed task (clearing bucket_id/bucket_state/
+// bucket_last_active_at) rather than deleting them. Returns
+// ErrNativeTaskNotFound if id doesn't match any row.
+func (s *Store) DeleteBucket(id string) error {
+ tx, err := s.db.Begin()
+ if err != nil {
+ return err
+ }
+ defer func() { _ = tx.Rollback() }()
+
+ if _, err := tx.Exec(`
+ UPDATE native_tasks SET bucket_id = '', bucket_state = '', bucket_last_active_at = NULL, updated_at = ? WHERE bucket_id = ?
+ `, config.Now(), id); err != nil {
+ return err
+ }
+ result, err := tx.Exec(`DELETE FROM maintenance_buckets WHERE id = ?`, id)
+ if err != nil {
+ return err
+ }
+ if err := checkRowsAffected(result); err != nil {
+ return err
+ }
+ return tx.Commit()
+}
+
// selectBucketCycle activates the top pick_n dormant items in the bucket's
// pool, scored by staleness (never-activated items first, then oldest
// bucket_last_active_at) with task priority as a tiebreaker. Activated items