-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
splitting into multiple schema.rs #3796
Conversation
Signed-off-by: forest1102 <[email protected]>
Signed-off-by: forest1102 <[email protected]>
Thanks for opening this PR. As written in the linked issue, we are generally interested in a solution to this problem, although I'm not sure if I personally would like to include a new In addition to the fundamental technical question, this PR would also need to have some tests if we decide to go this way. |
@weiznich
If this fits your thoughts too, I will add some tests. |
Just adding my 2cents since I also wanted to add SQLite attached table supports at some point. I think it would be better to have multiple print schéma occurrences so we can print each schema / attached table in a different file. Though the print sub schema could be used to print them all in the same file. I am actually wondering if we could remove the error when schema is set for sqlite in the CLI with this PR. |
@Sytten |
Unsure what your PR does, but if it allows printing multiple database schemas like the issue mentioned, then it should be possible to remove the following limitation in the sqlite inference:
Otherwise it doesn't fix the issue as mentioned and we should remove the fixes comment. |
@Sytten |
In your PR description is says |
@Sytten |
Thanks for writing up your reasoning. I do not really agree on these conclusions. I can follow your argumentation in so far that it's easier to implement it as new feature instead of extending an existing old feature and provide support for all the functionality the existing feature has, but for me that only sounds like getting around of doing the work for implementing the proper way. As for the CLI flags: Those could appear more than once. To summarize that: I would prefer having an implementation that uses several real print-schema instances instead of introducing a new striped down feature for this. |
@weiznich |
I'm sorry, but this still reads like an unnecessary duplication of features for me. I'm really not that sure that it is the right behavior ro share foreign key definitions between the different schemas. As for the CLI: Yes, that would likely require new CLI parameters to control the new functionality. |
@weiznich The New
|
I'm sorry but I cannot really follow what you are suggesting. Can you maybe try to provide some examples of the old and new (envisioned) |
@weiznich
diff_schema requires to set name parameter if print_schema is a hashmap, and the specified name of print_schema will be applied |
@forest1102 Thanks for spelling out that proposal. I think I would be fine with such a change, with some minor additions:
[print-schema.different-thing]
schema = "bar"
file = "src/schema_bar.rs" should be possible
|
@weiznich
|
Let's assume the following config: [print_schema]
file = "src/schema.rs"
filter={only_tables=["bar"]}
[print_schema.user]
file="user/src/schema.rs"
filter={only_tables=["users"]}
Then |
@weiznich [print_schema]
file = "src/schema.rs"
filter={only_tables=["bar"]}
[print_schema.user]
file="user/src/schema.rs"
filter={only_tables=["users"]} |
I would probably use an explicit insert into the HashMap after the parsing step using |
Signed-off-by: forest1102 <[email protected]>
@weiznich |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for the update. This looks now much more like what I had in mind 👍
I've left a few more or less stylistic comments and some questions that I would like to see answered. Other than that I would like to see at least one test for the generate schema part as well.
Finally it would be great if you can open a PR for the web-page as well that documents this new configuration file extension there as well: https://github.com/sgrif/diesel.rs-website/blob/master/src/guides/configuring-diesel-cli.md
diesel_cli/src/errors.rs
Outdated
@@ -58,4 +58,8 @@ pub enum Error { | |||
ColumnLiteralParseError(syn::Error), | |||
#[error("Failed to parse database url: {0}")] | |||
UrlParsingError(#[from] url::ParseError), | |||
#[error("Failed to parse CLI parameter: {0}")] | |||
ClapMatchesError(#[from] clap::parser::MatchesError), | |||
#[error("No print schema key with the name `{0}` exists")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we point out more explicitly that this refers to [print_schema.{0}]
entries in your diesel.toml
file?
(CI failures are caused by the recent rust release, I'm working on that) |
Signed-off-by: forest1102 <[email protected]>
Signed-off-by: forest1102 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now 👍. Thanks again for working on this. I will take care of the merge conflicts.
@weiznich |
In that case: Can you also put an entry into the |
Signed-off-by: forest1102 <[email protected]>
Signed-off-by: forest1102 <[email protected]>
Thanks again for working on this 👍 |
fixes #3799
I made an additional property
sub_print_schema
indiesel.toml
to output multipleschema.rs
.Tables included in the output code of
sub_print_schema
is first filtered byprint_schma
.