Make the inbox global instead of per-project
A card either sits in its owner's inbox (project_id AND status_id both NULL)
or belongs to exactly one project with a status in it (both set) -- enforced
by a CHECK constraint, never one without the other. The inbox is global to a
user now, not per-project: cards can move from a project into the inbox and
back into any status column of any project.
Backend
- migrations/009: rebuilds `cards` (SQLite can't relax NOT NULL / add a CHECK
in place) with a nullable project_id, a new owner_id (cards need direct
ownership once they can have no project), and the CHECK constraint. Cards
that had no status (the old per-project inbox) move to the new global inbox.
status_id's FK is now ON DELETE RESTRICT, not SET NULL -- nulling it alone
would violate the invariant, and there's no status-delete endpoint anyway.
- CardRepository: "column" is now (owner_id, project_id, status_id); every
method that dealt with a project's columns is generalised to also cover the
inbox and cross-project moves (orderColumn, idsInColumn, repack, ...).
- CardController/routes: single-card and ordering routes move to global,
since a card may have no project to nest them under --
GET/PATCH/DELETE /api/cards/{id}, PUT /api/cards/order (body now takes
project_id + status_id, both null for the inbox). New GET/POST
/api/inbox/cards. PATCH no longer accepts status_id -- moving a card, in or
out of a project, is exclusively PUT /api/cards/order now. A card created
directly in a project (POST /api/projects/{id}/cards) lands in its first
status, since a project card can't have no status.
- Tests: ProjectTest/CardStatusTest updated for the new routes; CardOrderTest
rewritten with full inbox/cross-project coverage. 57 tests pass.
Frontend
- New stores/inbox.ts (the global inbox) and lib/cardOrder.ts (the shared
PUT /api/cards/order call, used by both the sidebar and a project's board).
- AppSidebar: an Inbox section under the project list -- a vuedraggable list
in the same "kanban" drag group as every project's kanban columns, so a
card drags straight from the sidebar into whichever project is open, or
back out. (The empty-inbox state needed a real bugfix: it wasn't rendering
a <draggable> at all, so there was nowhere to drop a card back into an
empty inbox.) A drop reloads the inbox and, if a project is open, its cards.
- ProjectView's kanban board drops its synthetic Inbox column -- just the
real statuses now.
- DashboardView simplified to a plain grid of project tiles (name + card
count); its per-project "New" section is gone, since a project card can no
longer have no status.
- stores/cards.ts: patch/remove move to the global /api/cards/{id} routes.
Verified end-to-end against the rebuilt container (existing per-project-inbox
cards correctly migrated to the global inbox, 0 invariant violations) and the
dev server via headless Chrome: sidebar inbox -> project A "To do" -> back to
inbox -> project B "Done", full journey confirmed via the API at each step.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
-- The inbox becomes global to a user rather than per-project: a card now
|
||||
-- either belongs to nobody's project (project_id AND status_id both NULL --
|
||||
-- sitting in that user's inbox) or to exactly one project with a status in it
|
||||
-- (both set). Cards also gain a direct owner_id, since inbox cards have no
|
||||
-- project to derive ownership from.
|
||||
--
|
||||
-- SQLite can't relax an existing NOT NULL / add a CHECK to a live column, so
|
||||
-- the table is rebuilt.
|
||||
|
||||
CREATE TABLE cards_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
owner_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||
project_id INTEGER NULL REFERENCES projects (id) ON DELETE CASCADE,
|
||||
-- Was ON DELETE SET NULL; now that a project card must have a status
|
||||
-- (the CHECK below), silently nulling status_id on a deleted status would
|
||||
-- leave project_id orphaned without it. There is no status-delete
|
||||
-- endpoint yet, so this is only a safety net.
|
||||
status_id INTEGER NULL REFERENCES card_statuses (id) ON DELETE RESTRICT,
|
||||
text TEXT NOT NULL,
|
||||
complete INTEGER NOT NULL DEFAULT 0 CHECK (complete IN (0, 1)),
|
||||
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')),
|
||||
CHECK ((project_id IS NULL) = (status_id IS NULL))
|
||||
);
|
||||
|
||||
-- Existing cards with no status were sitting in their project's old
|
||||
-- per-project inbox column; that concept is gone, so they move to the (now
|
||||
-- global, per-owner) inbox -- project_id cleared alongside status_id.
|
||||
INSERT INTO cards_new (id, owner_id, project_id, status_id, text, complete, position, created_at, updated_at)
|
||||
SELECT c.id,
|
||||
p.owner_id,
|
||||
CASE WHEN c.status_id IS NULL THEN NULL ELSE c.project_id END,
|
||||
c.status_id,
|
||||
c.text, c.complete, c.position, c.created_at, c.updated_at
|
||||
FROM cards c
|
||||
JOIN projects p ON p.id = c.project_id;
|
||||
|
||||
DROP TABLE cards;
|
||||
ALTER TABLE cards_new RENAME TO cards;
|
||||
|
||||
CREATE INDEX idx_cards_owner_project_status_position
|
||||
ON cards (owner_id, project_id, status_id, position);
|
||||
CREATE INDEX idx_cards_status ON cards (status_id);
|
||||
|
||||
-- Re-pack every column -- including each owner's inbox -- to a dense 0..n-1,
|
||||
-- preserving relative order. Safe despite writing the table it reads: the CTE
|
||||
-- is evaluated against the pre-update snapshot.
|
||||
WITH ranked (id, rk) AS (
|
||||
SELECT id,
|
||||
row_number() OVER (
|
||||
PARTITION BY owner_id, project_id, status_id
|
||||
ORDER BY position, id
|
||||
) - 1
|
||||
FROM cards
|
||||
)
|
||||
UPDATE cards
|
||||
SET position = (SELECT rk FROM ranked WHERE ranked.id = cards.id);
|
||||
Reference in New Issue
Block a user