Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
66 lines
4.2 KiB
TypeScript
66 lines
4.2 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_structures_module_options_effects_type" AS ENUM('capacity_mass', 'production_multiplier', 'storage_slots');
|
|
CREATE TYPE "public"."enum_structures_module_options_category" AS ENUM('production', 'logistics', 'defense', 'utility');
|
|
CREATE TABLE "game_structures_installed_modules" (
|
|
"_order" integer NOT NULL,
|
|
"_parent_id" integer NOT NULL,
|
|
"id" varchar PRIMARY KEY NOT NULL,
|
|
"name" varchar NOT NULL,
|
|
"installed_at" timestamp(3) with time zone
|
|
);
|
|
|
|
CREATE TABLE "structures_module_options_effects" (
|
|
"_order" integer NOT NULL,
|
|
"_parent_id" varchar NOT NULL,
|
|
"id" varchar PRIMARY KEY NOT NULL,
|
|
"type" "enum_structures_module_options_effects_type" NOT NULL,
|
|
"value" numeric NOT NULL
|
|
);
|
|
|
|
CREATE TABLE "structures_module_options_materials" (
|
|
"_order" integer NOT NULL,
|
|
"_parent_id" varchar NOT NULL,
|
|
"id" varchar PRIMARY KEY NOT NULL,
|
|
"resource_id" integer NOT NULL,
|
|
"amount" numeric NOT NULL
|
|
);
|
|
|
|
CREATE TABLE "structures_module_options" (
|
|
"_order" integer NOT NULL,
|
|
"_parent_id" integer NOT NULL,
|
|
"id" varchar PRIMARY KEY NOT NULL,
|
|
"name" varchar NOT NULL,
|
|
"category" "enum_structures_module_options_category" DEFAULT 'utility' NOT NULL,
|
|
"description" varchar
|
|
);
|
|
|
|
ALTER TABLE "structures" ADD COLUMN "module_slots" numeric DEFAULT 0;
|
|
ALTER TABLE "game_structures_installed_modules" ADD CONSTRAINT "game_structures_installed_modules_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."game_structures"("id") ON DELETE cascade ON UPDATE no action;
|
|
ALTER TABLE "structures_module_options_effects" ADD CONSTRAINT "structures_module_options_effects_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."structures_module_options"("id") ON DELETE cascade ON UPDATE no action;
|
|
ALTER TABLE "structures_module_options_materials" ADD CONSTRAINT "structures_module_options_materials_resource_id_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("id") ON DELETE set null ON UPDATE no action;
|
|
ALTER TABLE "structures_module_options_materials" ADD CONSTRAINT "structures_module_options_materials_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."structures_module_options"("id") ON DELETE cascade ON UPDATE no action;
|
|
ALTER TABLE "structures_module_options" ADD CONSTRAINT "structures_module_options_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."structures"("id") ON DELETE cascade ON UPDATE no action;
|
|
CREATE INDEX "game_structures_installed_modules_order_idx" ON "game_structures_installed_modules" USING btree ("_order");
|
|
CREATE INDEX "game_structures_installed_modules_parent_id_idx" ON "game_structures_installed_modules" USING btree ("_parent_id");
|
|
CREATE INDEX "structures_module_options_effects_order_idx" ON "structures_module_options_effects" USING btree ("_order");
|
|
CREATE INDEX "structures_module_options_effects_parent_id_idx" ON "structures_module_options_effects" USING btree ("_parent_id");
|
|
CREATE INDEX "structures_module_options_materials_order_idx" ON "structures_module_options_materials" USING btree ("_order");
|
|
CREATE INDEX "structures_module_options_materials_parent_id_idx" ON "structures_module_options_materials" USING btree ("_parent_id");
|
|
CREATE INDEX "structures_module_options_materials_resource_idx" ON "structures_module_options_materials" USING btree ("resource_id");
|
|
CREATE INDEX "structures_module_options_order_idx" ON "structures_module_options" USING btree ("_order");
|
|
CREATE INDEX "structures_module_options_parent_id_idx" ON "structures_module_options" USING btree ("_parent_id");`)
|
|
}
|
|
|
|
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
DROP TABLE "game_structures_installed_modules" CASCADE;
|
|
DROP TABLE "structures_module_options_effects" CASCADE;
|
|
DROP TABLE "structures_module_options_materials" CASCADE;
|
|
DROP TABLE "structures_module_options" CASCADE;
|
|
ALTER TABLE "structures" DROP COLUMN "module_slots";
|
|
DROP TYPE "public"."enum_structures_module_options_effects_type";
|
|
DROP TYPE "public"."enum_structures_module_options_category";`)
|
|
}
|