Skip to content

Commit

Permalink
Merge pull request #3796 from forest1102/forest1102/issue1728
Browse files Browse the repository at this point in the history
splitting into multiple schema.rs
  • Loading branch information
weiznich authored Mar 5, 2024
2 parents 359da7e + 2343a5e commit 7c8cd02
Show file tree
Hide file tree
Showing 23 changed files with 869 additions and 143 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Increasing the minimal supported Rust version will always be coupled at least wi
* Logging in diesel-cli
* Support for libsqlite3-sys 0.28
* Add `sqlite-integer-primary-key-is-bigint` configuration option, usable with SQLite 3.37 or above, allowing to use `BigInt` for `INTEGER PRIMARY KEY` columns in SQLite for tables without the `WITHOUT ROWID` attribute ([SQLite doc](https://www.sqlite.org/lang_createtable.html#rowid)).
* Support for multiple `print_schema` entry in `diesel.toml` (e.g. `[print_schema.user1]`), which allows generating multiple schema.rs files

### Changed

Expand Down
9 changes: 6 additions & 3 deletions diesel_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ path = "src/main.rs"
doc = false

[dependencies]
chrono = { version = "0.4.20", default-features = false, features = ["clock", "std"] }
clap = { version = "4.0.2", features = ["cargo", "string"] }
chrono = { version = "0.4.20", default-features = false, features = [
"clock",
"std",
] }
clap = { version = "4.4.14", features = ["cargo", "string"] }
clap_complete = "4"
dotenvy = "0.15"
heck = "0.4.0"
serde = { version = "1.0.0", features = ["derive"] }
serde = { version = "1.0.193", features = ["derive", "std"] }
toml = "0.8"
url = { version = "2.2.2" }
libsqlite3-sys = { version = ">=0.17.2, <0.29.0", optional = true }
Expand Down
59 changes: 39 additions & 20 deletions diesel_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ use clap_complete::Shell;

use crate::print_schema;

fn position_sensitive_flag(arg: Arg) -> Arg {
arg.num_args(0)
.value_parser(clap::value_parser!(bool))
.default_missing_value("true")
.default_value("false")
}

pub fn build_cli() -> Command {
let database_arg = Arg::new("DATABASE_URL")
.long("database-url")
Expand Down Expand Up @@ -168,20 +175,24 @@ pub fn build_cli() -> Command {
.help("Table names to filter."),
)
.arg(
Arg::new("only-tables")
position_sensitive_flag(Arg::new("only-tables"))
.short('o')
.long("only-tables")
.action(ArgAction::SetTrue)
.help("Only include tables from table-name that matches regexp.")
.conflicts_with("except-tables"),
.action(ArgAction::Append)
.help("Only include tables from table-name that matches regexp."),
)
.arg(
Arg::new("except-tables")
position_sensitive_flag(Arg::new("except-tables"))
.short('e')
.long("except-tables")
.action(ArgAction::SetTrue)
.help("Exclude tables from table-name that matches regex.")
.conflicts_with("only-tables"),
.action(ArgAction::Append)
.help("Exclude tables from table-name that matches regex."),
)
.arg(
Arg::new("schema-key")
.long("schema-key")
.action(clap::ArgAction::Append)
.help("select schema key from diesel.toml, use 'default' for print_schema without key."),
),
)
.subcommand_required(true)
Expand Down Expand Up @@ -238,60 +249,62 @@ pub fn build_cli() -> Command {
.help("Table names to filter."),
)
.arg(
Arg::new("only-tables")
position_sensitive_flag(Arg::new("only-tables"))
.short('o')
.long("only-tables")
.action(ArgAction::SetTrue)
.action(ArgAction::Append)
.help("Only include tables from table-name that matches regexp.")
.conflicts_with("except-tables"),
)
.arg(
Arg::new("except-tables")
position_sensitive_flag(Arg::new("except-tables"))
.short('e')
.long("except-tables")
.action(ArgAction::SetTrue)
.action(ArgAction::Append)
.help("Exclude tables from table-name that matches regex.")
.conflicts_with("only-tables"),
)
.arg(
Arg::new("with-docs")
position_sensitive_flag(Arg::new("with-docs"))
.long("with-docs")
.action(ArgAction::SetTrue)
.action(ArgAction::Append)
.help("Render documentation comments for tables and columns."),
)
.arg(
Arg::new("with-docs-config")
.long("with-docs-config")
.help("Render documentation comments for tables and columns.")
.num_args(1)
.action(ArgAction::Append)
.value_parser(PossibleValuesParser::new(print_schema::DocConfig::VARIANTS_STR)),
)
.arg(
Arg::new("column-sorting")
.long("column-sorting")
.help("Sort order for table columns.")
.num_args(1)
.action(ArgAction::Append)
.value_parser(PossibleValuesParser::new(["ordinal_position", "name"])),
)
.arg(
Arg::new("patch-file")
.long("patch-file")
.num_args(1)
.action(ArgAction::Append)
.value_parser(clap::value_parser!(std::path::PathBuf))
.help("A unified diff file to be applied to the final schema."),
)
.arg(
Arg::new("import-types")
.long("import-types")
.num_args(1..)
.action(ArgAction::Append)
.action(clap::ArgAction::Append)
.number_of_values(1)
.help("A list of types to import for every table, separated by commas."),
)
.arg(
Arg::new("generate-custom-type-definitions")
position_sensitive_flag(Arg::new("generate-custom-type-definitions"))
.long("no-generate-missing-sql-type-definitions")
.action(ArgAction::SetTrue)
.action(ArgAction::Append)
.help("Generate SQL type definitions for types not provided by diesel"),
)
.arg(
Expand All @@ -303,9 +316,15 @@ pub fn build_cli() -> Command {
.help("A list of derives to implement for every automatically generated SqlType in the schema, separated by commas."),
)
.arg(
Arg::new("sqlite-integer-primary-key-is-bigint")
Arg::new("schema-key")
.long("schema-key")
.action(ArgAction::Append)
.default_values(["default"])
.help("select schema key from diesel.toml, use 'default' for print_schema without key."),
).arg(
position_sensitive_flag(Arg::new("sqlite-integer-primary-key-is-bigint"))
.long("sqlite-integer-primary-key-is-bigint")
.action(ArgAction::SetTrue)
.action(ArgAction::Append)
.help(
"For SQLite 3.37 and above, detect `INTEGER PRIMARY KEY` columns as `BigInt`, \
when the table isn't declared with `WITHOUT ROWID`.\n\
Expand Down
Loading

0 comments on commit 7c8cd02

Please sign in to comment.