Skip to content

Commit 7f0ac3d

Browse files
authored
fix misleading dbinit_equals_sum_of_all_up advice (#8059)
Currently, if the test `dbinit_equals_sum_of_all_up` detects that a new column has been added in a different order from what's in `dbinit`, it prints this message: > Statistics did not match. This often means that in dbinit.sql, a new column > was added into the middle of a table rather than to the end. If that is the > case: > > * Change dbinit.sql to add the column to the end of the table. > * Update nexus/db-model/src/schema.rs and the corresponding > Queryable/Insertable struct with the new column ordering. I think the advice given here is not quite right. The ordering of columns in `schema.rs` and in the `Queryable`/`Insertable` struct(s) must be the same, but the ordering in `schema.rs` does NOT need to match that in the SQL schema. This is important because, in some cases, a `Queryable` or `Insertable` type consists of multiple nested structs using `#[diesel(embed)]`, and the ordering in `schema.rs` may depend on that --- fields grouped into the same embedded struct must appear in a particular order so that they are part of the correct struct. This does NOT need to be the same order in `dbinit.sql`, and following the advice this assertion failure currently gives will result in much weirder compilation errors if fields are reordered in `schema.rs` in a way that doesn't match the struct ordering required by use of `#[diesel(embed)]`. Therefore, I've removed the second bullet point, and changed the assertion to just suggest changing the ordering in `dbinit.sql`.
1 parent 71dace9 commit 7f0ac3d

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

nexus/tests/integration_tests/schema.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,8 @@ impl InformationSchema {
552552
other.statistics,
553553
"Statistics did not match. This often means that in dbinit.sql, a new \
554554
column was added into the middle of a table rather than to the end. \
555-
If that is the case:\n\n \
556-
\
557-
* Change dbinit.sql to add the column to the end of the table.\n\
558-
* Update nexus/db-model/src/schema.rs and the corresponding \
559-
Queryable/Insertable struct with the new column ordering."
555+
If that is the case, change dbinit.sql to add the column to the \
556+
end of the table.\n"
560557
);
561558
similar_asserts::assert_eq!(self.sequences, other.sequences);
562559
similar_asserts::assert_eq!(self.pg_indexes, other.pg_indexes);

0 commit comments

Comments
 (0)