Add per-workspace auto-incrementing issue numbers with a configurable prefix, producing identifiers like "JIA-1" instead of truncated UUIDs. Database: - Add issue_prefix and issue_counter to workspace table - Add number column to issue table with UNIQUE(workspace_id, number) - Backfill existing issues with sequential numbers Backend: - Issue creation atomically increments counter in a transaction - API responses include number and identifier fields - Support issue lookup by identifier format (KEY-N) - Workspace prefix auto-generated from name, customizable via API Frontend: - Display identifier in list rows and issue detail breadcrumb - Add issue_prefix to Workspace type, number/identifier to Issue type
36 lines
1.3 KiB
SQL
36 lines
1.3 KiB
SQL
-- Add issue_prefix and issue_counter to workspace for human-readable issue IDs.
|
|
ALTER TABLE workspace
|
|
ADD COLUMN issue_prefix TEXT NOT NULL DEFAULT '',
|
|
ADD COLUMN issue_counter INT NOT NULL DEFAULT 0;
|
|
|
|
-- Add per-workspace issue number.
|
|
ALTER TABLE issue
|
|
ADD COLUMN number INT NOT NULL DEFAULT 0;
|
|
|
|
-- Backfill: generate issue_prefix from workspace name (first 3 uppercase chars).
|
|
UPDATE workspace SET issue_prefix = UPPER(
|
|
LEFT(REGEXP_REPLACE(name, '[^a-zA-Z]', '', 'g'), 3)
|
|
);
|
|
|
|
-- Fallback for workspaces with empty prefix after cleanup.
|
|
UPDATE workspace SET issue_prefix = 'WS' WHERE issue_prefix = '';
|
|
|
|
-- Backfill: assign sequential numbers to existing issues per workspace.
|
|
WITH numbered AS (
|
|
SELECT id, workspace_id,
|
|
ROW_NUMBER() OVER (PARTITION BY workspace_id ORDER BY created_at ASC) AS rn
|
|
FROM issue
|
|
)
|
|
UPDATE issue SET number = numbered.rn
|
|
FROM numbered WHERE issue.id = numbered.id;
|
|
|
|
-- Update workspace counters to match.
|
|
UPDATE workspace SET issue_counter = COALESCE(
|
|
(SELECT MAX(number) FROM issue WHERE issue.workspace_id = workspace.id), 0
|
|
);
|
|
|
|
-- Add unique constraint.
|
|
ALTER TABLE issue ADD CONSTRAINT uq_issue_workspace_number UNIQUE (workspace_id, number);
|
|
|
|
-- Index for fast lookup by workspace + number.
|
|
CREATE INDEX idx_issue_workspace_number ON issue(workspace_id, number);
|