Add non-null constraint to zones.number#13992
Conversation
All images
No significant size changes |
📝 WalkthroughWalkthroughThis PR enforces a NOT NULL constraint on the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
zones.number
There was a problem hiding this comment.
In other recent migrations, e.g. the pair of 20260115220136_courses__branch__nonnull_constraint_add.sql and 20260115220137_courses__branch__nonnull_constraint_validate.sql, we first added an invalid constraint, then validated it and added the NOT NULL constraint (which Postgres could immediately validate because of the existence of the other constraint). Can you say why you didn't take a similar approach here?
There was a problem hiding this comment.
I put up sbdchd/squawk#910 so we can potentially enable this in the future
There was a problem hiding this comment.
Looks like this was resolved in ff79009?
(Do we need to add "NEVER amend and force push unless specifically requested" to AGENTS.md?)
There was a problem hiding this comment.
yes, i'll add that to this PR
|
Once we get to postgres 18 we can do this: https://neon.com/postgresql/postgresql-18/not-null-as-not-valid |
Add migration to set NOT NULL constraint on zones.number column. Update related type definitions to reflect the schema change. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
f97a4b8 to
ff79009
Compare
Add NOT NULL constraints to the `number` column in: alternative_groups, assessment_instances, assessment_modules, course_instance_access_rules, job_sequences, questions, tags, and topics. This follows the pattern from PR #13992 (zones table) with a two-phase migration approach: add CHECK constraints with NOT VALID, then validate + set NOT NULL + drop CHECK. Two tables required backfills: topics (37 NULLs) and assessment_instances (1 NULL). These use batched migrations to safely handle large datasets. The remaining 6 tables have no NULL values, so their constraints are added and validated directly. This ensures the database accurately reflects the application's type constraints via Zod schemas. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Description
Add a database migration to make the
numbercolumn in thezonestable NOT NULL. This change has been verified to not affect production data, as no rows contain NULL values for this column. Noted in #13991.Updates related type definitions to reflect the schema change:
ZoneSchemain db-types.ts to remove.nullable()from thenumberfieldin production
Testing
Build passes successfully with no type errors. Test fixtures updated to reflect the new constraint.