1
0
Fork 0
polaris-task-force/src/migrations/20260918_064326_add_compound_parent.ts
2026-09-20 02:43:23 -04:00

16 lines
945 B
TypeScript

import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "game_structures" ADD COLUMN "parent_structure_id" integer;
ALTER TABLE "game_structures" ADD CONSTRAINT "game_structures_parent_structure_id_game_structures_id_fk" FOREIGN KEY ("parent_structure_id") REFERENCES "public"."game_structures"("id") ON DELETE set null ON UPDATE no action;
CREATE INDEX "game_structures_parent_structure_idx" ON "game_structures" USING btree ("parent_structure_id");`)
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "game_structures" DROP CONSTRAINT "game_structures_parent_structure_id_game_structures_id_fk";
DROP INDEX "game_structures_parent_structure_idx";
ALTER TABLE "game_structures" DROP COLUMN "parent_structure_id";`)
}