diff --git a/backend/internal/db/queries/tablos.sql b/backend/internal/db/queries/tablos.sql index c50a8c9..8bd452c 100644 --- a/backend/internal/db/queries/tablos.sql +++ b/backend/internal/db/queries/tablos.sql @@ -1,5 +1,5 @@ -- name: ListTablosByUser :many -SELECT id, user_id, title, description, color, created_at, updated_at +SELECT id, user_id, title, description, color, created_at, updated_at, status FROM tablos WHERE user_id = $1 ORDER BY created_at DESC; @@ -12,6 +12,7 @@ SELECT tablos.id, tablos.color, tablos.created_at, tablos.updated_at, + tablos.status, COALESCE(count(unread_messages.id), 0)::bigint AS discussion_unread_count FROM tablos LEFT JOIN discussion_read_states AS read_state @@ -27,24 +28,35 @@ LEFT JOIN discussion_messages AS unread_messages OR unread_messages.created_at > last_read_message.created_at ) WHERE tablos.user_id = sqlc.arg(user_id) -GROUP BY tablos.id, tablos.user_id, tablos.title, tablos.description, tablos.color, tablos.created_at, tablos.updated_at +GROUP BY tablos.id, tablos.user_id, tablos.title, tablos.description, tablos.color, tablos.created_at, tablos.updated_at, tablos.status ORDER BY tablos.created_at DESC; -- name: GetTabloByID :one -SELECT id, user_id, title, description, color, created_at, updated_at +SELECT id, user_id, title, description, color, created_at, updated_at, status FROM tablos WHERE id = $1 AND user_id = $2; -- name: InsertTablo :one INSERT INTO tablos (user_id, title, description, color) VALUES ($1, $2, $3, $4) -RETURNING id, user_id, title, description, color, created_at, updated_at; +RETURNING id, user_id, title, description, color, created_at, updated_at, status; -- name: UpdateTablo :one UPDATE tablos SET title = $2, description = $3, color = $4, updated_at = now() WHERE id = $1 -RETURNING id, user_id, title, description, color, created_at, updated_at; +RETURNING id, user_id, title, description, color, created_at, updated_at, status; -- name: DeleteTablo :exec DELETE FROM tablos WHERE id = $1 AND user_id = $2; + +-- name: ListTabloProgressByIDs :many +-- Batch aggregation: one query for all tablos on the dashboard (D-06). +-- Counts all tasks regardless of etape assignment. +SELECT + tablo_id, + COUNT(*) FILTER (WHERE status = 'done')::int AS done_tasks, + COUNT(*)::int AS total_tasks +FROM tasks +WHERE tablo_id = ANY(@tablo_ids::uuid[]) +GROUP BY tablo_id; diff --git a/backend/migrations/0010_tablo_status.sql b/backend/migrations/0010_tablo_status.sql new file mode 100644 index 0000000..4eec820 --- /dev/null +++ b/backend/migrations/0010_tablo_status.sql @@ -0,0 +1,7 @@ +-- +goose Up +ALTER TABLE tablos + ADD COLUMN status text NOT NULL DEFAULT 'active' + CHECK (status IN ('active', 'archived')); + +-- +goose Down +ALTER TABLE tablos DROP COLUMN status;