1
0
Fork 0

fix(migrations): backfill grid columns before NOT NULL on data-bearing table

The generated migration added grid_x/grid_y as numeric NOT NULL without a
default, which fails on prod where game_structures_stored_resources already
has rows ('column contains null values'). Add the columns with DEFAULT 0 to
backfill existing rows, then drop the default to match the target schema.
This commit is contained in:
Jason Fraley 2026-08-16 18:23:33 -04:00
parent 931c60e234
commit 56b79e142e

View file

@ -376,8 +376,10 @@ export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
ALTER TABLE "missions" ALTER COLUMN "game_details_game_setup_mission_file_id" DROP NOT NULL;
ALTER TABLE "structures_auto_generated_resources" ALTER COLUMN "min_frequency" SET DEFAULT '1';
ALTER TABLE "game_structures_stored_resources" ADD COLUMN "grid_x" numeric NOT NULL;
ALTER TABLE "game_structures_stored_resources" ADD COLUMN "grid_y" numeric NOT NULL;
ALTER TABLE "game_structures_stored_resources" ADD COLUMN "grid_x" numeric DEFAULT 0 NOT NULL;
ALTER TABLE "game_structures_stored_resources" ADD COLUMN "grid_y" numeric DEFAULT 0 NOT NULL;
ALTER TABLE "game_structures_stored_resources" ALTER COLUMN "grid_x" DROP DEFAULT;
ALTER TABLE "game_structures_stored_resources" ALTER COLUMN "grid_y" DROP DEFAULT;
ALTER TABLE "game_structures_stored_resources" ADD COLUMN "rotated" boolean DEFAULT false;
ALTER TABLE "game_structures" ADD COLUMN "faction_id" integer;
ALTER TABLE "users" ADD COLUMN "discord_id" varchar;