mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-03 19:20:07 +02:00
Squashed history of PR #4892 (pr-4784-fix). Makes spaces the primary navigation and working surface, on the "associations bind at creation time only" model. Model - Issue <-> space is the only enforced ownership (per-space numbering). Parent/child and project<->space associations only seed defaults at creation; cross-space/child and project-association validations are removed. - Moving an issue renumbers it and records the old identifier in issue_identifier_alias; API/CLI lookups and GitHub branch/PR auto-linking fall back to the alias, so old identifiers resolve forever. - Membership drives only the sidebar and personal defaults — never access. Anyone can configure any space's member set wholesale (PUT /api/spaces/{id}/members); saving an empty set archives the space behind a confirm. - Per-user space order (workspace_space_member.sort_order, fractional): drag-sorted sidebar, "my first space" is the personal issue-creation default; the workspace default space backs headless creation (agents/CLI/Slack) and system placement. Surfaces - Sidebar: joined-spaces section (drag reorder, row -> space page, per-group persisted collapse), Workspace group with a More menu, Settings demoted to a footer icon. - /space/:key/{issues,projects,autopilots,settings} — space surfaces reuse shared page components; a routed /space/new create page (replacing the earlier create-space modal), reserved key "NEW" so it can never collide with a real space's /space/:key detail page. - Issue detail moves to /issue/:id (identifier-first, Linear-style; old /issues/:id redirects); create dialogs lead with a required space pill. - Agent runtime brief now carries Space context (id/key/name) through the daemon claim -> TaskContextForEnv -> prompt pipeline, with a "## Space Context" section and --space on issue create/update in both brief renderers, matching Project's existing treatment. - zh-Hans: Space translated to 空间 across locales and conventions.zh.mdx. Fixes along the way - Cache membership judgment gains the space dimension + space_changed WS flag. - Silent skip on default-space lookup during invite acceptance is now a hard failure (no space-less members). - Backfilled space_id into ~28 raw-SQL Go test fixtures across internal/handler and cmd/server that predated migration 132's NOT NULL cutover. - Fixed a resolve-loop bug in the IssueDetail identifier wrapper (mount/ unmount cycle on resolution failure) and gave it its own loading skeleton instead of a blank screen while resolving. - reserved-slugs generator's stale hardcoded doc-comment example synced back to /create-space. Verification - go build ./..., go vet ./..., go test ./... all clean. - pnpm typecheck (core/views/web/desktop) clean. - packages/views: 162 files / 1656 tests passing. - pnpm generate:reserved-slugs produces no diff. Follow-ups tracked in docs/follow-ups/space-rollout.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
90 lines
3.1 KiB
SQL
90 lines
3.1 KiB
SQL
-- name: ListProjects :many
|
|
SELECT * FROM project
|
|
WHERE project.workspace_id = $1
|
|
AND (sqlc.narg('space_id')::uuid IS NULL OR EXISTS (
|
|
SELECT 1 FROM project_space pt
|
|
WHERE pt.project_id = project.id
|
|
AND pt.workspace_id = project.workspace_id
|
|
AND pt.space_id = sqlc.narg('space_id')::uuid
|
|
))
|
|
AND (sqlc.narg('status')::text IS NULL OR project.status = sqlc.narg('status'))
|
|
AND (sqlc.narg('priority')::text IS NULL OR project.priority = sqlc.narg('priority'))
|
|
ORDER BY created_at DESC;
|
|
|
|
-- name: GetProject :one
|
|
SELECT * FROM project
|
|
WHERE id = $1;
|
|
|
|
-- name: GetProjectInWorkspace :one
|
|
SELECT * FROM project
|
|
WHERE id = $1 AND workspace_id = $2;
|
|
|
|
-- name: CreateProject :one
|
|
INSERT INTO project (
|
|
workspace_id, title, description, icon, status,
|
|
lead_type, lead_id, priority
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8
|
|
) RETURNING *;
|
|
|
|
-- name: UpdateProject :one
|
|
UPDATE project SET
|
|
title = COALESCE(sqlc.narg('title'), title),
|
|
description = sqlc.narg('description'),
|
|
icon = sqlc.narg('icon'),
|
|
status = COALESCE(sqlc.narg('status'), status),
|
|
priority = COALESCE(sqlc.narg('priority'), priority),
|
|
lead_type = sqlc.narg('lead_type'),
|
|
lead_id = sqlc.narg('lead_id'),
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
RETURNING *;
|
|
|
|
-- name: DeleteProject :exec
|
|
-- Defense-in-depth: workspace_id is a SQL-layer tenant guard. See DeleteIssue.
|
|
DELETE FROM project WHERE id = $1 AND workspace_id = $2;
|
|
|
|
-- name: CountIssuesByProject :one
|
|
SELECT count(*) FROM issue
|
|
WHERE project_id = $1;
|
|
|
|
-- name: GetProjectIssueStats :many
|
|
SELECT project_id,
|
|
count(*)::bigint AS total_count,
|
|
count(*) FILTER (WHERE status IN ('done', 'cancelled'))::bigint AS done_count
|
|
FROM issue
|
|
WHERE project_id = ANY(sqlc.arg('project_ids')::uuid[])
|
|
GROUP BY project_id;
|
|
|
|
-- name: ListProjectSpaces :many
|
|
SELECT wt.* FROM workspace_space wt
|
|
JOIN project_space pt ON pt.space_id = wt.id AND pt.workspace_id = wt.workspace_id
|
|
WHERE pt.workspace_id = $1
|
|
AND pt.project_id = $2
|
|
ORDER BY wt.name ASC, wt.created_at ASC;
|
|
|
|
-- name: ListProjectSpacesByProjects :many
|
|
SELECT pt.project_id, wt.id, wt.workspace_id, wt.name, wt.key, wt.description,
|
|
wt.icon, wt.issue_counter, wt.archived_at, wt.archived_by,
|
|
wt.created_by, wt.created_at, wt.updated_at
|
|
FROM project_space pt
|
|
JOIN workspace_space wt ON wt.id = pt.space_id AND wt.workspace_id = pt.workspace_id
|
|
WHERE pt.workspace_id = $1
|
|
AND pt.project_id = ANY(sqlc.arg('project_ids')::uuid[])
|
|
ORDER BY pt.project_id, wt.name ASC, wt.created_at ASC;
|
|
|
|
-- name: AddProjectSpace :exec
|
|
INSERT INTO project_space (workspace_id, project_id, space_id)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT (project_id, space_id) DO NOTHING;
|
|
|
|
-- name: ReplaceProjectSpaces :exec
|
|
WITH deleted AS (
|
|
DELETE FROM project_space
|
|
WHERE workspace_id = sqlc.arg('workspace_id')
|
|
AND project_id = sqlc.arg('project_id')
|
|
AND NOT (space_id = ANY(sqlc.arg('space_ids')::uuid[]))
|
|
)
|
|
INSERT INTO project_space (workspace_id, project_id, space_id)
|
|
SELECT sqlc.arg('workspace_id'), sqlc.arg('project_id'), unnest(sqlc.arg('space_ids')::uuid[])
|
|
ON CONFLICT (project_id, space_id) DO NOTHING; |