* feat: add ticket numbers to cards with workspace prefix - Add cardNumber to cards - Add cardPrefix/cardCounter to workspace - Populate initial prefixes and numbers via new migration - Introduce generateWorkspacePrefix util and export it - Include cardNumber in card-related API responses and search results - Render and display tickets as PREFIX-NUMBER in UI - Update Card component to accept ticketNumber - Update CardModal and board cards to show number when available - Add cardNumber to CommandPalette search results type * feat: regen migration * feat: enhance card and workspace schemas with cardNumber and indexing - Updated the card repository to allocate card numbers atomically per workspace. - Modified the card schema to include a cardNumber field and added an index on listId and cardNumber for improved query performance. - Enhanced the workspace schema to include an index on cardPrefix for optimized lookups. - Adjusted the migration journal to reflect the new schema changes and their timestamps. - Updated the regex in workspace repository to allow alphanumeric prefixes in ticket IDs. --------- Co-authored-by: Henry <henry_ball@hotmail.co.uk>
48 lines
1.8 KiB
SQL
48 lines
1.8 KiB
SQL
ALTER TABLE "card" ADD COLUMN "cardNumber" integer;--> statement-breakpoint
|
|
ALTER TABLE "workspace" ADD COLUMN "cardPrefix" varchar(10) DEFAULT '' NOT NULL;--> statement-breakpoint
|
|
ALTER TABLE "workspace" ADD COLUMN "cardCounter" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
CREATE INDEX IF NOT EXISTS "card_list_number_idx" ON "card" USING btree ("listId","cardNumber");--> statement-breakpoint
|
|
CREATE INDEX IF NOT EXISTS "workspace_card_prefix_idx" ON "workspace" USING btree ("cardPrefix");--> statement-breakpoint
|
|
|
|
-- Populate cardPrefix for existing workspaces from their name
|
|
UPDATE "workspace"
|
|
SET "cardPrefix" = (
|
|
SELECT CASE
|
|
WHEN array_length(words, 1) = 1 THEN UPPER(LEFT(words[1], 3))
|
|
ELSE UPPER(LEFT(array_to_string(ARRAY(
|
|
SELECT LEFT(w, 1) FROM unnest(words) AS w WHERE w != ''
|
|
), ''), 4))
|
|
END
|
|
FROM (
|
|
SELECT regexp_split_to_array(trim("name"), '\s+') AS words
|
|
) sub
|
|
)
|
|
WHERE "cardPrefix" = '';--> statement-breakpoint
|
|
|
|
-- Assign sequential cardNumber to existing cards (including soft-deleted),
|
|
-- ordered by createdAt, scoped to workspace. Deleted cards still receive a
|
|
-- number so future un-archive/restore flows can keep their ticket ID.
|
|
WITH numbered AS (
|
|
SELECT
|
|
c.id,
|
|
ROW_NUMBER() OVER (PARTITION BY b."workspaceId" ORDER BY c."createdAt", c.id) AS rn
|
|
FROM "card" c
|
|
JOIN "list" l ON c."listId" = l.id
|
|
JOIN "board" b ON l."boardId" = b.id
|
|
WHERE c."cardNumber" IS NULL
|
|
)
|
|
UPDATE "card" c
|
|
SET "cardNumber" = n.rn
|
|
FROM numbered n
|
|
WHERE c.id = n.id;--> statement-breakpoint
|
|
|
|
-- Update cardCounter on each workspace to the max cardNumber assigned
|
|
UPDATE "workspace" w
|
|
SET "cardCounter" = COALESCE((
|
|
SELECT MAX(c."cardNumber")
|
|
FROM "card" c
|
|
JOIN "list" l ON c."listId" = l.id
|
|
JOIN "board" b ON l."boardId" = b.id
|
|
WHERE b."workspaceId" = w.id AND c."cardNumber" IS NOT NULL
|
|
), 0);
|