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

Introduce a config file for Diesel CLI #1629

Closed
sgrif opened this Issue Apr 10, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@sgrif
Member

sgrif commented Apr 10, 2018

The main goal of this file is to allow us to deprecate infer_schema!, and provide ways to customize the output of diesel 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 both diesel print-schema and Diesel CLI. The goal was to not force people to write their table! 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-schema was 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-schema after any migration command, outputting to that file. Directly running diesel print-schema should continue to print to STDOUT, and should not be affected by this option.

Customizing the output

diesel print-schema still 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:

  • Ignoring certain tables
  • Adding additional type imports

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 .patch file which gets applied.

Minor details

The config file should be found by the first of the following which is present:

  • A global --config-file flag on the CLI
  • The DIESEL_CONFIG_FILE environment variable
  • A file called diesel.toml located in the same directory as Cargo.toml

For any configuration options which can be configured both by the config file and by command line options, the config file should win.

@sgrif

This comment has been minimized.

Member

sgrif commented Apr 11, 2018

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

@sgrif

This comment has been minimized.

Member

sgrif commented May 16, 2018

@diesel-rs/core Do we have anything left to do on this?

@Eijebong

This comment has been minimized.

Member

Eijebong commented May 16, 2018

Documentation probably. I couldn't even find it

@weiznich

This comment has been minimized.

Contributor

weiznich commented May 16, 2018

Yes documentation is missing.
Sean added some check that we really add the documentation.

@weiznich

This comment has been minimized.

Contributor

weiznich commented May 28, 2018

Diesel 1.3 was released some days ago containing this feature.

@weiznich weiznich closed this May 28, 2018

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