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.1 KiB
TypeScript
48 lines
3.1 KiB
TypeScript
import { MigrateUpArgs, MigrateDownArgs, sql } from "@payloadcms/db-postgres";
|
|
|
|
export async function up({ db }: MigrateUpArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
CREATE TYPE "public"."enum_game_structures_staff_positions_position_type" AS ENUM('administrative', 'technical', 'other');
|
|
CREATE TABLE "game_structures_labor_requirements" (
|
|
"_order" integer NOT NULL,
|
|
"_parent_id" integer NOT NULL,
|
|
"id" varchar PRIMARY KEY NOT NULL,
|
|
"classification_id" integer NOT NULL,
|
|
"required_headcount" numeric DEFAULT 0 NOT NULL,
|
|
"max_headcount" numeric,
|
|
"enforced_salary" numeric
|
|
);
|
|
|
|
CREATE TABLE "game_structures_staff_positions" (
|
|
"_order" integer NOT NULL,
|
|
"_parent_id" integer NOT NULL,
|
|
"id" varchar PRIMARY KEY NOT NULL,
|
|
"position_type" "enum_game_structures_staff_positions_position_type" NOT NULL,
|
|
"max" numeric,
|
|
"enforced_salary" numeric
|
|
);
|
|
|
|
ALTER TABLE "game_structures" ADD COLUMN "maintenance_cost" numeric DEFAULT 0;
|
|
ALTER TABLE "labor_classifications" ADD COLUMN "available_headcount" numeric DEFAULT 0;
|
|
ALTER TABLE "game_rules" ADD COLUMN "staff_hiring_enabled" boolean DEFAULT false;
|
|
ALTER TABLE "game_rules" ADD COLUMN "staff_hiring_disabled_message" varchar;
|
|
ALTER TABLE "game_structures_labor_requirements" ADD CONSTRAINT "game_structures_labor_requirements_classification_id_labor_classifications_id_fk" FOREIGN KEY ("classification_id") REFERENCES "public"."labor_classifications"("id") ON DELETE set null ON UPDATE no action;
|
|
ALTER TABLE "game_structures_labor_requirements" ADD CONSTRAINT "game_structures_labor_requirements_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."game_structures"("id") ON DELETE cascade ON UPDATE no action;
|
|
ALTER TABLE "game_structures_staff_positions" ADD CONSTRAINT "game_structures_staff_positions_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."game_structures"("id") ON DELETE cascade ON UPDATE no action;
|
|
CREATE INDEX "game_structures_labor_requirements_order_idx" ON "game_structures_labor_requirements" USING btree ("_order");
|
|
CREATE INDEX "game_structures_labor_requirements_parent_id_idx" ON "game_structures_labor_requirements" USING btree ("_parent_id");
|
|
CREATE INDEX "game_structures_labor_requirements_classification_idx" ON "game_structures_labor_requirements" USING btree ("classification_id");
|
|
CREATE INDEX "game_structures_staff_positions_order_idx" ON "game_structures_staff_positions" USING btree ("_order");
|
|
CREATE INDEX "game_structures_staff_positions_parent_id_idx" ON "game_structures_staff_positions" USING btree ("_parent_id");`);
|
|
}
|
|
|
|
export async function down({ db }: MigrateDownArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
DROP TABLE "game_structures_labor_requirements" CASCADE;
|
|
DROP TABLE "game_structures_staff_positions" CASCADE;
|
|
ALTER TABLE "game_structures" DROP COLUMN "maintenance_cost";
|
|
ALTER TABLE "labor_classifications" DROP COLUMN "available_headcount";
|
|
ALTER TABLE "game_rules" DROP COLUMN "staff_hiring_enabled";
|
|
ALTER TABLE "game_rules" DROP COLUMN "staff_hiring_disabled_message";
|
|
DROP TYPE "public"."enum_game_structures_staff_positions_position_type";`);
|
|
}
|