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>
48 lines
3.6 KiB
TypeScript
48 lines
3.6 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 TYPE "public"."enum_npc_staffing_position_type" AS ENUM('labor', 'administrative', 'technical', 'other');
|
|
CREATE TYPE "public"."enum_npc_staffing_status" AS ENUM('active', 'terminated');
|
|
ALTER TYPE "public"."enum_game_event_logs_target_collection" ADD VALUE 'npc-staffing' BEFORE 'structures';
|
|
CREATE TABLE "npc_staffing" (
|
|
"id" serial PRIMARY KEY NOT NULL,
|
|
"npc_id" integer NOT NULL,
|
|
"structure_id" integer NOT NULL,
|
|
"position_type" "enum_npc_staffing_position_type" DEFAULT 'labor' NOT NULL,
|
|
"position_title" varchar NOT NULL,
|
|
"salary" numeric DEFAULT 0,
|
|
"status" "enum_npc_staffing_status" DEFAULT 'active',
|
|
"hired_at" timestamp(3) with time zone,
|
|
"terminated_at" timestamp(3) with time zone,
|
|
"notes" 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 "payload_locked_documents_rels" ADD COLUMN "npc_staffing_id" integer;
|
|
ALTER TABLE "npc_staffing" ADD CONSTRAINT "npc_staffing_npc_id_game_npcs_id_fk" FOREIGN KEY ("npc_id") REFERENCES "public"."game_npcs"("id") ON DELETE set null ON UPDATE no action;
|
|
ALTER TABLE "npc_staffing" ADD CONSTRAINT "npc_staffing_structure_id_game_structures_id_fk" FOREIGN KEY ("structure_id") REFERENCES "public"."game_structures"("id") ON DELETE set null ON UPDATE no action;
|
|
CREATE INDEX "npc_staffing_npc_idx" ON "npc_staffing" USING btree ("npc_id");
|
|
CREATE INDEX "npc_staffing_structure_idx" ON "npc_staffing" USING btree ("structure_id");
|
|
CREATE INDEX "npc_staffing_updated_at_idx" ON "npc_staffing" USING btree ("updated_at");
|
|
CREATE INDEX "npc_staffing_created_at_idx" ON "npc_staffing" USING btree ("created_at");
|
|
ALTER TABLE "payload_locked_documents_rels" ADD CONSTRAINT "payload_locked_documents_rels_npc_staffing_fk" FOREIGN KEY ("npc_staffing_id") REFERENCES "public"."npc_staffing"("id") ON DELETE cascade ON UPDATE no action;
|
|
CREATE INDEX "payload_locked_documents_rels_npc_staffing_id_idx" ON "payload_locked_documents_rels" USING btree ("npc_staffing_id");`)
|
|
}
|
|
|
|
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
ALTER TABLE "npc_staffing" DISABLE ROW LEVEL SECURITY;
|
|
DROP TABLE "npc_staffing" CASCADE;
|
|
ALTER TABLE "payload_locked_documents_rels" DROP CONSTRAINT "payload_locked_documents_rels_npc_staffing_fk";
|
|
|
|
ALTER TABLE "game_event_logs" ALTER COLUMN "target_collection" SET DATA TYPE text;
|
|
DROP TYPE "public"."enum_game_event_logs_target_collection";
|
|
CREATE TYPE "public"."enum_game_event_logs_target_collection" AS ENUM('game-structures', 'game-vehicles', 'game-npcs', 'structures', 'resources', 'assets', 'vehicles', 'factions', 'missions', 'campaigns', 'users', 'technologies', 'maps', 'shipments', 'bank-accounts', 'bank-transactions', 'ledger-entries', 'locker-storages', 'loadouts', 'market-listings', 'market-negotiations', 'evaluations', 'tickets', 'wiki-pages', 'wiki-revisions', 'wiki-templates', 'game-servers', 'assignment-transfers');
|
|
ALTER TABLE "game_event_logs" ALTER COLUMN "target_collection" SET DATA TYPE "public"."enum_game_event_logs_target_collection" USING "target_collection"::"public"."enum_game_event_logs_target_collection";
|
|
DROP INDEX "payload_locked_documents_rels_npc_staffing_id_idx";
|
|
ALTER TABLE "payload_locked_documents_rels" DROP COLUMN "npc_staffing_id";
|
|
DROP TYPE "public"."enum_npc_staffing_position_type";
|
|
DROP TYPE "public"."enum_npc_staffing_status";`)
|
|
}
|