Files
project-manager/migrations/006_add_card_statuses.sql
T
aneurinandClaude Sonnet 5 c47c800d01 Add per-project card statuses and a kanban board
Statuses
- Migration 006: card_statuses table (project-scoped) and cards.status_id, a
  nullable FK with ON DELETE SET NULL. Every new project is seeded with
  "To do" / "Doing" / "Done"; GET /api/projects/{id}/statuses lists them.
- New cards have no status -- they sit in an "inbox" until moved.

Project view
- Full-width and tabbed: "All tasks" (a flat list, sorted by name
  case-insensitively) and "Kanban" (Inbox plus one column per status).
- Drag a card within or between columns to reorder / restatus; the Inbox
  column has its own name + Add form.

Ordering
- Migration 007: `position` is now a dense 0..n-1 rank within a
  (project_id, status_id) column, not a project-wide order. New composite
  index idx_cards_project_status_position; existing rows re-ranked.
- PUT /api/projects/{id}/cards/order takes { status_id, card_ids } and sets one
  column's contents and order, re-parenting moved-in cards and re-packing their
  source column in a single transaction. PATCH status_id appends the card to the
  end of the destination column.

58 phpunit tests pass; the frontend type-checks and builds.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 13:37:17 +01:00

33 lines
1.4 KiB
SQL

-- Project-specific card statuses. Every project gets a "To do" / "Doing" /
-- "Done" set when it is created (see CardStatusRepository::seedDefaults); the
-- backfill below covers projects that already existed.
CREATE TABLE IF NOT EXISTS card_statuses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
name TEXT NOT NULL,
position INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
);
CREATE INDEX IF NOT EXISTS idx_card_statuses_project_position
ON card_statuses (project_id, position);
-- Nullable, and left NULL for existing cards: a card without a status sits in
-- the project "inbox" until the user gives it one. Losing a status (a deleted
-- status row) clears the link rather than removing the card.
ALTER TABLE cards
ADD COLUMN status_id INTEGER REFERENCES card_statuses (id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS idx_cards_status ON cards (status_id);
-- Backfill: give every pre-existing project the default status set.
INSERT INTO card_statuses (project_id, name, position)
SELECT p.id, d.name, d.position
FROM projects p
CROSS JOIN (
SELECT 'To do' AS name, 0 AS position
UNION ALL SELECT 'Doing', 1
UNION ALL SELECT 'Done', 2
) d;