-
Notifications
You must be signed in to change notification settings - Fork 649
Cleanup: remove email
field on User
in Rust code
#1888
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
Comments
I would like to work on this! |
@hbina great!! Please let me know if you have any questions!!! |
So if I am reading your suggestions correctly, the idea is to:
Correct? From |
You've got it!
Correct! The error message is complaining about what the database is returning, that the database results don't match what diesel was expecting for the |
So, I think the only non-trivial cases are error number 9, 15, and 17. The rest are just simply Diesel error that should be fixed when the table schema are updated. I will copy them here for ease. |
If we are ditching Lines 161 to 170 in 3248b4d
There are a bunch of tests that will need to be revised when we do make the change. |
We'll need to pass the email into the Let me know if that doesn't answer your questions! |
Hi @hbina, I saw that you had some questions in chat, I'm going to try to answer your questions here :) This issue is important because we need the Rust code to stop using the It's hard to see, but by default, Diesel selects all the columns from a table. For this issue, we need to tell it to select all the columns from the users table except for the email column. So there will be some temporary code changes needed for this issue that will be undone by #1891, and that's exactly correct. Does that make sense? I see this commit you posted in chat, it's close and I'm going to add some comments on it! Please ask more questions if I'm still not being clear! |
Hi! Thanks for the feedback. I have applied the changes that you requested. Is this sufficient? I think I am getting the hang of it. I will try to work on it tonight after school, thank you! |
…cents Preparation to drop `email` in User in Rust codes Related: #1888 This commit(s) prepares the migration to dropping `email` column from the `User` table. Here, I introduce a new intermediate type called `UserNoEmailType`. Copied from my latest commit: Every queries out of `User`'stable should now be converted into an intermediate type called `UserNoEmailType`. This is done by selecting only the appropriate columns which is defined in `user::ALL_COLUMNS` (notice that it excludes `email`) This could be renamed, I guess. Conversion from this type to `User` is simply a copy except that `email` returned will always be `None`. I think its possible to remove `email` from User directly because its not actually the mirror of `User`'s table. The mirror struct is actually `NewUser`.
Should this be closed? |
This seems to have been solved by #1911 and #1891 if I remember correctly @thiagoarrais |
Going to close this in favor of the above comments. Thanks for the heads-up! |
This is for someone who likes fixing compiler errors and knows or wants to learn about diesel :)
As of this PR, I'm pretty sure we don't use the
email
field onUser
anywhere directly anymore (and if we aren't, we shouldn't be). Instead, we have anemails
table that joins tousers
.So we can clean this field up and be less confusing about where the user's email is.
The first step is removing all usage of this field from the Rust code, but leaving the column on the
users
table in the database. Once the Rust code is no longer using the column, we can safely migrate the database to drop that column.But this issue is for just the first step. The way I'd go about it, which isn't the only way so feel free to go about this the way you'd like, is to remove this line from the
User
struct definition and try to compile.A lot of the error messages are going to be because the default behavior of diesel is to select all columns of a table and expect the struct definition to match. Removing the email field from the struct will break that assumption. We need to change the Rust code to never select the email field from the database. We have this problem with krate too, which has a column having to do with full text search that we never want to select in the Rust code.
The way the krate code works is it defines a type alias and a constant named
ALL_COLUMNS
:crates.io/src/models/krate.rs
Lines 50 to 76 in 0a6d3fb
And then everywhere that we select a krate from the database, use that constant instead. For example, selecting all crates happens with the
all
function:crates.io/src/models/krate.rs
Lines 245 to 247 in 0a6d3fb
ALL_COLUMNS
constant and another type alias namedAll
:crates.io/src/models/krate.rs
Line 81 in 0a6d3fb
Other convenience functions like
Crate::by_name
:crates.io/src/models/krate.rs
Lines 237 to 239 in 0a6d3fb
filter
calls offall
to avoid having to duplicate the.select(ALL_COLUMNS)
bit.Extracting some helper functions might be an intermediate step that can be done in a separate commit from, but informed by, the fixes to the compilation errors. In other words, the errors can tell you where we're currently selecting users from the database directly that we could maybe be using a helper function instead. Extracting those could be done in a commit that passes tests as it would be a smaller refactoring that wouldn't change behavior. Then the commit that removes the field from the struct would need fewer changes in fewer places, hopefully. This may not actually be the case, or may not actually make the changes easier, and it may be just the way I work. If this paragraph doesn't make sense, ignore it!
The text was updated successfully, but these errors were encountered: