1
0
Fork 0
polaris-task-force/src/migrations/20261123_073019_add_tech_tree_notes.ts
Z8MB1E 48556c3688 feat(tech-tree): add note nodes with optional frontend visibility
Planners can now drop annotation cards on the Tech Tree canvas without inventing fake technologies. Notes live in their own tech-tree-notes collection (title, body, treePosition) and carry no prerequisites, costs, approval workflow or research state, so the layout engine, edge builder and research rules never see them.

showOnFrontend defaults to false, making notes a backend authoring aid; ticking it publishes the amber card read-only to the member tech tree, which queries showOnFrontend = true.

Canvas work: amber NoteNode card with no connection handles, NoteDialog for create/edit/delete, a New Note toolbar button (technologies:create gated), viewport-centre placement, and namespaced note-<id> React Flow ids so note and technology ids can never collide. Note drags, Save positions and Auto-arrange reuse the single-statement bulk /api/tech-tree/positions write by sending collection: "tech-tree-notes"; no PATCH-per-note path was added.

Also fixes the note card body being clipped by the inherited line-height: the classification strip and footer now have fixed heights with leading-none, and the body takes the remaining flex space instead of line-clamp.

Tests: tech-tree-notes.int.spec.ts (defaults, required title, publication filter, in-place edits, note layout and id namespacing) plus note coverage in tech-tree-positions.int.spec.ts. Migration 20261123_073019_add_tech_tree_notes must be run on prod after deploy.
2026-11-23 03:11:36 -05:00

39 lines
2.3 KiB
TypeScript

import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
await db.execute(sql`
CREATE TABLE "tech_tree_notes" (
"id" serial PRIMARY KEY NOT NULL,
"title" varchar NOT NULL,
"body" varchar,
"show_on_frontend" boolean DEFAULT false,
"tree_position_x" numeric,
"tree_position_y" numeric,
"updated_at" timestamp(3) with time zone DEFAULT now() NOT NULL,
"created_at" timestamp(3) with time zone DEFAULT now() NOT NULL
);
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "tech_tree_notes_find" boolean DEFAULT false;
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "tech_tree_notes_create" boolean DEFAULT false;
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "tech_tree_notes_update" boolean DEFAULT false;
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "tech_tree_notes_delete" boolean DEFAULT false;
ALTER TABLE "payload_locked_documents_rels" ADD COLUMN "tech_tree_notes_id" integer;
CREATE INDEX "tech_tree_notes_updated_at_idx" ON "tech_tree_notes" USING btree ("updated_at");
CREATE INDEX "tech_tree_notes_created_at_idx" ON "tech_tree_notes" USING btree ("created_at");
ALTER TABLE "payload_locked_documents_rels" ADD CONSTRAINT "payload_locked_documents_rels_tech_tree_notes_fk" FOREIGN KEY ("tech_tree_notes_id") REFERENCES "public"."tech_tree_notes"("id") ON DELETE cascade ON UPDATE no action;
CREATE INDEX "payload_locked_documents_rels_tech_tree_notes_id_idx" ON "payload_locked_documents_rels" USING btree ("tech_tree_notes_id");`)
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "tech_tree_notes" DISABLE ROW LEVEL SECURITY;
DROP TABLE "tech_tree_notes" CASCADE;
ALTER TABLE "payload_locked_documents_rels" DROP CONSTRAINT "payload_locked_documents_rels_tech_tree_notes_fk";
DROP INDEX "payload_locked_documents_rels_tech_tree_notes_id_idx";
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN "tech_tree_notes_find";
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN "tech_tree_notes_create";
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN "tech_tree_notes_update";
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN "tech_tree_notes_delete";
ALTER TABLE "payload_locked_documents_rels" DROP COLUMN "tech_tree_notes_id";`)
}