Skip to content
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

[cli] skip generating entity for ignored tables #837

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ pub enum GenerateSubcommands {
)]
tables: Option<String>,

#[clap(
value_parser,
long,
use_value_delimiter = true,
takes_value = true,
default_value = "seaql_migrations",
help = "Skip generating entity file for specified tables (comma separated)"
)]
ignore_tables: Vec<String>,

#[clap(
value_parser,
long,
Expand Down
8 changes: 8 additions & 0 deletions sea-orm-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub async fn run_generate_command(
expanded_format,
include_hidden_tables,
tables,
ignore_tables,
max_connections,
output_dir,
database_schema,
Expand Down Expand Up @@ -87,6 +88,10 @@ pub async fn run_generate_command(
}
};

let filter_skip_tables = |table: &String| -> bool {
!ignore_tables.contains(table)
};

let database_name = if !is_sqlite {
// The database name should be the first element of the path string
//
Expand Down Expand Up @@ -130,6 +135,7 @@ pub async fn run_generate_command(
.into_iter()
.filter(|schema| filter_tables(&schema.info.name))
.filter(|schema| filter_hidden_tables(&schema.info.name))
.filter(|schema| filter_skip_tables(&schema.info.name))
.map(|schema| schema.write())
.collect()
}
Expand All @@ -145,6 +151,7 @@ pub async fn run_generate_command(
.into_iter()
.filter(|schema| filter_tables(&schema.name))
.filter(|schema| filter_hidden_tables(&schema.name))
.filter(|schema| filter_skip_tables(&schema.name))
.map(|schema| schema.write())
.collect()
}
Expand All @@ -161,6 +168,7 @@ pub async fn run_generate_command(
.into_iter()
.filter(|schema| filter_tables(&schema.info.name))
.filter(|schema| filter_hidden_tables(&schema.info.name))
.filter(|schema| filter_skip_tables(&schema.info.name))
.map(|schema| schema.write())
.collect()
}
Expand Down