From 6e92f957332d2f2d3337c1fb6d03cbd3bf74d5a9 Mon Sep 17 00:00:00 2001 From: aamoghS Date: Sat, 14 Nov 2026 18:39:19 -0500 Subject: [PATCH] fix(db): clean push and hold initiative.max_members positive club_project.tech loses its array default. drizzle-kit read it back in a different spelling and re-applied it on every push; the seed, the only writer, always sets it. With that and the earlier primary key fix, a push against an up-to-date database now reports no changes. Adds initiative_max_members_check (null or > 0), which the API already enforces. packages/db/sql/2026-11-initiative-max-members.sql clears the one production row at 0, an archived initiative with no applications, and runs before this deploys. --- .../db/sql/2026-11-initiative-max-members.sql | 15 +++++++++++++++ packages/db/src/schemas/club-projects.ts | 8 +++----- packages/db/src/schemas/initiatives.ts | 4 +++- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 packages/db/sql/2026-11-initiative-max-members.sql diff --git a/packages/db/sql/2026-11-initiative-max-members.sql b/packages/db/sql/2026-11-initiative-max-members.sql new file mode 100644 index 00000000..1e66aa16 --- /dev/null +++ b/packages/db/sql/2026-11-initiative-max-members.sql @@ -0,0 +1,15 @@ +-- Clears the one initiative whose max_members is 0, so the check added in the +-- same change (initiative_max_members_check: null or > 0) can be created. The +-- API has refused 0 for a while ("zero would be an initiative nobody can +-- join"); null means uncapped. In production the only such row is archived +-- with no applications, so the change reaches nobody. +-- +-- Run against production BEFORE that change deploys, or push fails adding the +-- check. One transaction; a second run changes nothing. + +begin; + +update "initiative" set "max_members" = null, "updated_at" = now() + where "max_members" <= 0; + +commit; \ No newline at end of file diff --git a/packages/db/src/schemas/club-projects.ts b/packages/db/src/schemas/club-projects.ts index c1fcb02f..5734df9a 100644 --- a/packages/db/src/schemas/club-projects.ts +++ b/packages/db/src/schemas/club-projects.ts @@ -7,7 +7,6 @@ import { integer, index, } from "drizzle-orm/pg-core"; -import { sql } from "drizzle-orm"; import { initiatives } from "./initiatives"; // The public roster on `/` and `/projects`. Separate from `initiative`, which @@ -35,10 +34,9 @@ export const clubProjects = pgTable( // they ever sign in, and past leads have graduated. leadName: text("lead_name"), summary: text("summary").notNull(), - tech: text("tech") - .array() - .notNull() - .default(sql`'{}'::text[]`), + // No array default: drizzle-kit reads it back in a different spelling and + // re-applied it on every push. The seed, the only writer, always sets it. + tech: text("tech").array().notNull(), repoUrl: text("repo_url"), joinUrl: text("join_url"), capacityNote: text("capacity_note"), diff --git a/packages/db/src/schemas/initiatives.ts b/packages/db/src/schemas/initiatives.ts index eb36f3f1..996d4c43 100644 --- a/packages/db/src/schemas/initiatives.ts +++ b/packages/db/src/schemas/initiatives.ts @@ -8,8 +8,9 @@ import { index, unique, uniqueIndex, + check, } from "drizzle-orm/pg-core"; -import { relations } from "drizzle-orm"; +import { relations, sql } from "drizzle-orm"; import { users } from "./auth"; // Club initiatives: things a project leader runs year-round that members @@ -99,6 +100,7 @@ export const initiatives = pgTable( (table) => [ index("initiative_leader_idx").on(table.leaderUserId), index("initiative_status_idx").on(table.status), + check("initiative_max_members_check", sql`${table.maxMembers} > 0`), ], );