New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`diesel migration redo` gives confusing error when no migrations have been run #671

Closed
sgrif opened this Issue Feb 10, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@sgrif
Member

sgrif commented Feb 10, 2017

To reproduce:

  • set DATABASE_URL to a database which exists, but has has no migrations run
  • Run diesel migration redo

Expected behavior:

  • An error message along the lines of "There aren't any migrations to redo. Did you forget to diesel migration run?" appears. Non-zero exit code

Actual behavior:

  • Unexpected null for non-null column is output with no additional information
@sgrif

This comment has been minimized.

Member

sgrif commented Feb 10, 2017

The issue occurs because MAX(col) returns NULL if the table is empty. The SqlType of Max<T> is T::SqlType in Diesel 0.10. https://docs.rs/diesel/0.10.1/diesel/expression/dsl/struct.Max.html Semantically we should probably just change the return type of this (along with min, avg, etc) to all return T::SqlType::IntoNullable.

sgrif added a commit that referenced this issue Feb 10, 2017

Change the return type of `max` and `min` to be nullable
Regardless of the input type, these functions return `NULL` on an empty
table. This both makes the behavior of these functions correctly mirror
the underlying database semantics, and also mirror the behavior of the
equivalent methods on `Iterator`. We need to make the same change for
`avg` and `sum`, but they're structured differently and will be a
separate PR.

Fixes #671.

@sgrif sgrif closed this in #672 Feb 11, 2017

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