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 upIntroduce a config file for Diesel CLI #1629
Comments
sgrif
added this to the 1.3 milestone
Apr 10, 2018
sgrif
referenced this issue
Apr 11, 2018
Merged
Add a config file for Diesel CLI, autorun `print-schema` #1630
This comment has been minimized.
|
Unresolved question: if generating schema fails, should we abort the transaction used to run the migrations? I'm leaning towards no, since we don't have hooks to do so, and we don't run migrations in a transaction on MySQL |
This comment has been minimized.
|
@diesel-rs/core Do we have anything left to do on this? |
This comment has been minimized.
|
Documentation probably. I couldn't even find it |
This comment has been minimized.
|
Yes documentation is missing. |
This comment has been minimized.
|
Diesel 1.3 was released some days ago containing this feature. |
weiznich
closed this
May 28, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sgrif commentedApr 10, 2018
The main goal of this file is to allow us to deprecate
infer_schema!, and provide ways to customize the output ofdiesel print-schema. If there are other things that it'd make sense for us to configure, leave a comment on this issue. This file should not handle things like database URLs, as it's meant to be checked into version control.Getting rid of
infer_schema!infer_schema!predates bothdiesel print-schemaand Diesel CLI. The goal was to not force people to write theirtable!declarations by hand, when they represent something we can lookup elsewhere. However, that macro complicates builds since it requires a database connection at compile time. It is very opaque what's happening (especially if something goes wrong), and it's impossible to change the output.However, we didn't deprecate the macro when
diesel print-schemawas added. I still think it is a useful macro to have at the very beginning of your project. Early on, the schema changes much more frequently, and it's a pain to have to remember to run this second command when you run migrations.Having a config file will fix this. We can have an option in this file for where the schema file should be located. If this option is present, we will automatically run
print-schemaafter any migration command, outputting to that file. Directly runningdiesel print-schemashould continue to print to STDOUT, and should not be affected by this option.Customizing the output
diesel print-schemastill has its own problems though. One of the biggest reasons we moved towards this is that it allows you to change the output (just by editing the file). However, this is extremely annoying since you have to redo those changes every time.I do not think we can ever catch every change that people want to make to this file, but we can catch some of the most common ones. I'd like this file to support:
This list is pretty short. There are other common customizations that are omitted (skipping certain joins, adding additional joins, renaming columns, changing the type of a column). The two customizations I've listed have obvious and clear ways to configure them. Renaming columns for example, I would want to see a concrete proposal for the configuration format.
Finally, as a catch-all, we should also support providing a
.patchfile which gets applied.Minor details
The config file should be found by the first of the following which is present:
--config-fileflag on the CLIDIESEL_CONFIG_FILEenvironment variablediesel.tomllocated in the same directory asCargo.tomlFor any configuration options which can be configured both by the config file and by command line options, the config file should win.