Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upImprove documentation for timestamp helpers #1891
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0xazure commentedOct 21, 2018
Setup
Versions
Feature Flags
Problem Description
I just started working with Diesel as part of a Rocket server app I'm building, and I'm working my way through Rocket's guide to get up to speed on the ins and outs of working with Rocket. I've gotten to the point where I need to set up my database, so I jumped from Rocket's section on state with databases (using Diesel) to Diesel's guide and started following along.
In the past I've used ORMs like Sequelize, which automatically adds columns for
created_atandupdated_atto generated models, and I know I want to include these fields in my models in Diesel. However, I ran into some confusion regarding the timestamp helpers while following the guide, and while I think I understand how all the related parts fit together I think the explanations could be smoothed out a bit for users new to Diesel.First, the guide mentions:
As far as I can tell, this hasn't been true since #991 landed; the
migrations/directory is not empty, and the generatedmigrations/00000000000000_diesel_initial_setupcaught me off guard because the guide said themigrations/folder should be empty.I think it would also be really helpful to see these files be written in a similar way to how the path of user-generated migrations are output to the console when migrations are created.
Instead of:
I think it would be helpful to see:
Next, I think the explanation comment inside
up.sqlcould be tweaked to better clarify the provided function.I think "
to automatically set a column" should actually read "to automatically update a column" or "to automatically update the value of a column"; if I understand correctly the timestamp in theupdated_atcolumn gets updated to the current time as one would expect if Diesel is automatically managing this column.It also wasn't immediately clear to me, but am I correct that the example in the explanation comment is SQL for an example migration to create a
Userstable, and as such would be created in a different file? My initial impression was that code that followed the pattern of the example would be added tomigrations/00000000000000_diesel_initial_setup/up.sql, but I don't think that initial impression is correct.If the example would in fact live in a different file, I think it would be very helpful to annotate the SQL snipped with an example file name, such as
Filename: migrations/XXXXXXXXXXXXX_create_users.sqljust as the Rust book does for multiple files in, for example, the section onmodand the file system. I think this would help clarify for those new to Diesel that code like the explanation comment's example should actually live in a separate file.I would be very happy to put up a PR (or more) to address the above, and I would really appreciate any feedback you might have about these suggestions. As I only just started working with Diesel today, there may have been something I missed in the guide or other docs about this feature, but I'd still like to see if we can improve this feature and make it a bit more visible.
Checklist
closed if this is not the case)