Skip to content

Conversation

@Lindsay-X
Copy link
Member

@Lindsay-X Lindsay-X commented Dec 15, 2025

  • Added a formName field to the form table to support named forms in the admin UI and APIs.
  • Migrated all tables except for form and season use composite keys that include seasonCode
    • form table is heavily referenced by other entities --> composite keys would require propagating seasonCode into every dependent table which would cause join complexities

import { season } from "./season";

export const form = pgTable("form", {
formId: uuid("formId")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formId should also be composite keyed with seasonCode

"when": 1764220440632,
"tag": "0001_cascade_behaviour",
"when": 1765780179980,
"tag": "0000_cynical_supreme_intelligence",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we name the migration file like "0000_init" instead of the auto generated names

Copy link
Member

@BlazingAsher BlazingAsher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

form table is heavily referenced by other entities --> composite keys would require propagating seasonCode into every dependent table which would cause join complexities

I would push back on this. The point of stamping seasonCode everywhere is to avoid cross-tenant leakage. It really should be everywhere. What join complexities are you foreseeing? I could possibly see an issue if you're trying to join two things that are from different seasons, but that should be intentionally hard because that's a cross-tenant access.

.array()
.default(sql`ARRAY[]::text[]`),
},
(t) => [primaryKey({ columns: [t.formQuestionId, t.seasonCode] })],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be formQuestionid, formId, seasonCode

},
(t) => [unique().on(t.seasonCode, t.userId, t.formId)],
(t) => [
primaryKey({ columns: [t.formResponseId, t.seasonCode] }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formResponseId, formId, seasonCode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to actually add formId into the PK

},
),
winnerId: uuid("winnerId"),
loserId: uuid("loserId"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should FK to the hacker table userId (assuming you drop hackerId)

volunteerId: uuid("volunteerId")
.primaryKey()
.default(sql`uuidv7()`),
volunteerId: uuid("volunteerId").default(sql`uuidv7()`),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For hacker, mentor, sponsor, and this one, I think you should get rid of the "role"Id and make the PK solely the userId, seasonCode.

There should never be more than one "hacker" per userId and seasonCode, so there shouldn't be a need to introduce another Id for it.

Copy link
Member

@BlazingAsher BlazingAsher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address comments before merging


eventId: uuid("eventId").notNull(),

userId: uuid("userId").notNull(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably FK this to users as well

},
(t) => [unique().on(t.seasonCode, t.userId, t.formId)],
(t) => [
primaryKey({ columns: [t.formResponseId, t.seasonCode] }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to actually add formId into the PK

@Lindsay-X Lindsay-X merged commit 66b0d72 into main Dec 27, 2025
2 checks passed
danielp1218 pushed a commit that referenced this pull request Dec 27, 2025
* fix: change to composite keys and add form names to form

* fix: fix format

* fix: added form composite keys, remove specific user id

* fix: format

* fix: added missing keys and constraints

* fix: format fix
danielp1218 added a commit that referenced this pull request Jan 4, 2026
* feat: create route-specific auth handlers

* fix: better dev support and error handling

* feat: update usertype logic

* apply suggestions from code review

* Add formName and migrate season-scoped tables to composite keys (#2)

* fix: change to composite keys and add form names to form

* fix: fix format

* fix: added form composite keys, remove specific user id

* fix: format

* fix: added missing keys and constraints

* fix: format fix

* fix: better user type unit tests

---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants