Skip to content

[dbinit.sql] Make some columns NOT NULL#9976

Merged
smklein merged 7 commits into
mainfrom
not-null-columns
Mar 13, 2026
Merged

[dbinit.sql] Make some columns NOT NULL#9976
smklein merged 7 commits into
mainfrom
not-null-columns

Conversation

@smklein

@smklein smklein commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

This schema change aligns the database with existing diesel models in Rust

Part of #9966

Comment thread schema/crdb/fewer-nullable-columns/up1.sql
Comment thread schema/crdb/fewer-nullable-columns/up10.sql Outdated
Comment thread schema/crdb/fewer-nullable-columns/up11.sql
Comment thread schema/crdb/fewer-nullable-columns/up2.sql
Comment thread schema/crdb/fewer-nullable-columns/up4.sql
Comment thread schema/crdb/fewer-nullable-columns/up6.sql Outdated
Comment thread schema/crdb/fewer-nullable-columns/up7.sql
Comment thread schema/crdb/fewer-nullable-columns/up8.sql
Comment thread schema/crdb/fewer-nullable-columns/up9.sql
Comment thread schema/crdb/dbinit.sql Outdated
@smklein

smklein commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator Author

I think I've addressed all comments here - thanks everyone for the feedback. Anyone willing to give this a look / approval? Or are there any outstanding concerns?

@smklein

smklein commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator Author

Unless anyone has further objections, I'll plan on landing this about 24 hours from now. Happy to pause for additional feedback, but otherwise I'd like to keep the ball rolling on aligning diesel's schema with Cockroach's.

@smklein smklein merged commit 254a399 into main Mar 13, 2026
16 checks passed
@smklein smklein deleted the not-null-columns branch March 13, 2026 17:21
jgallagher added a commit that referenced this pull request May 4, 2026
…e strict (#10155)

Staged on top of #10122, which strengthened the types used for BGP peers
in the external API.

* Always represent unnumbered peers as a `NULL` address
* Add `CHECK` constraints that prevent storing the addresses `0.0.0.0`
or `::` to ensure we don't have any leftover sentinel values
* For the three tables that required the address to be non-NULL because
it was part of a composite primary key, add a new synthetic `id` primary
key (a random UUID)

The database migrations are similar in spirit to #9976: while we're not
correcting mismatches between diesel and CRDB here, we are introducing
migrations that _could_ fail if real databases have data we don't expect
(e.g., an address of `0.0.0.0` in the table where we expect unnumbered
peers to be represented as NULL). The tactic I went with in the
migration is:

* If there's only one unnumbered peer (treating NULL, 0.0.0.0, :: all as
possibilities), convert it to `NULL`.
* If there are multiple, keep one (preferring `NULL` then `0.0.0.0`) and
delete the rest. This shouldn't delete anything unless someone has some
already-invalid-at-runtime data.

There's a data migration test that should cover a sample of each kind of
possibly-invalid input and confirm the above behavior.

One other thing that snuck in here is a bugfix for #10151.
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.

8 participants