1
0
Fork 0
polaris-task-force/src/migrations/20260905_210310_labor_classifications.ts
Z8MB1E b2718b3633 feat(base): add npc staffing and labor classification collections
Adds the npc-staffing and labor-classifications collections, a shared staffing field factory applied to both structure blueprints (Staffing Defaults group) and game structure instances, blueprint-derived staffing defaults on game structure create, staff-hiring toggles on Game Rules, and their database migrations.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-06 01:24:08 -04:00

51 lines
3.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 "labor_classifications" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar NOT NULL,
"key" varchar NOT NULL,
"default_unit_salary" numeric,
"description" varchar,
"updated_at" timestamp(3) with time zone DEFAULT now() NOT NULL,
"created_at" timestamp(3) with time zone DEFAULT now() NOT NULL
);
ALTER TABLE "npc_staffing" ADD COLUMN "labor_classification_id" integer;
ALTER TABLE "payload_locked_documents_rels" ADD COLUMN "labor_classifications_id" integer;
CREATE UNIQUE INDEX "labor_classifications_name_idx" ON "labor_classifications" USING btree ("name");
CREATE UNIQUE INDEX "labor_classifications_key_idx" ON "labor_classifications" USING btree ("key");
CREATE INDEX "labor_classifications_updated_at_idx" ON "labor_classifications" USING btree ("updated_at");
CREATE INDEX "labor_classifications_created_at_idx" ON "labor_classifications" USING btree ("created_at");
ALTER TABLE "npc_staffing" ADD CONSTRAINT "npc_staffing_labor_classification_id_labor_classifications_id_fk" FOREIGN KEY ("labor_classification_id") REFERENCES "public"."labor_classifications"("id") ON DELETE set null ON UPDATE no action;
ALTER TABLE "payload_locked_documents_rels" ADD CONSTRAINT "payload_locked_documents_rels_labor_classifications_fk" FOREIGN KEY ("labor_classifications_id") REFERENCES "public"."labor_classifications"("id") ON DELETE cascade ON UPDATE no action;
CREATE INDEX "npc_staffing_labor_classification_idx" ON "npc_staffing" USING btree ("labor_classification_id");
CREATE INDEX "payload_locked_documents_rels_labor_classifications_id_idx" ON "payload_locked_documents_rels" USING btree ("labor_classifications_id");
ALTER TABLE "npc_staffing" DROP COLUMN "labor_classification";
DROP TYPE "public"."enum_npc_staffing_labor_classification";
INSERT INTO "labor_classifications" ("name", "key", "default_unit_salary", "description") VALUES
('General', 'general', NULL, NULL),
('Doctor', 'doctor', NULL, NULL),
('Mechanic', 'mechanic', NULL, NULL),
('Engineer', 'engineer', NULL, NULL),
('Security', 'security', NULL, NULL),
('Other', 'other', NULL, NULL)
ON CONFLICT ("key") DO NOTHING;`);
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
CREATE TYPE "public"."enum_npc_staffing_labor_classification" AS ENUM('general', 'doctor', 'mechanic', 'engineer', 'security', 'other');
ALTER TABLE "labor_classifications" DISABLE ROW LEVEL SECURITY;
DROP TABLE "labor_classifications" CASCADE;
ALTER TABLE "npc_staffing" DROP CONSTRAINT "npc_staffing_labor_classification_id_labor_classifications_id_fk";
ALTER TABLE "payload_locked_documents_rels" DROP CONSTRAINT "payload_locked_documents_rels_labor_classifications_fk";
DROP INDEX "npc_staffing_labor_classification_idx";
DROP INDEX "payload_locked_documents_rels_labor_classifications_id_idx";
ALTER TABLE "npc_staffing" ADD COLUMN "labor_classification" "enum_npc_staffing_labor_classification";
ALTER TABLE "npc_staffing" DROP COLUMN "labor_classification_id";
ALTER TABLE "payload_locked_documents_rels" DROP COLUMN "labor_classifications_id";`);
}