Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ let user = user::ActiveModel::builder()
* [sea-orm-cli] Added `--column-extra-derives` https://github.com/SeaQL/sea-orm/pull/2212
* [sea-orm-cli] Added `--big-integer-type=i32` to use i32 for bigint (for SQLite)
* [sea-orm-cli] Fix codegen to not generate relations to filtered entities https://github.com/SeaQL/sea-orm/pull/2913
* [sea-orm-cli] Added `--experimental-preserve-user-modifications` https://github.com/SeaQL/sea-orm/pull/2755 https://github.com/SeaQL/sea-orm/pull/2964
* Added `Model::try_set`
* Added new error variant `BackendNotSupported`. Previously, it panics with e.g. "Database backend doesn't support RETURNING" https://github.com/SeaQL/sea-orm/pull/2630
```rust
Expand Down
25 changes: 21 additions & 4 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::{ArgAction, ArgGroup, Parser, Subcommand, ValueEnum};
#[cfg(feature = "codegen")]
use dotenvy::dotenv;
use std::ffi::OsStr;

#[cfg(feature = "codegen")]
use crate::{handle_error, run_generate_command, run_migrate_command};
Expand Down Expand Up @@ -359,17 +360,19 @@ pub enum GenerateSubcommands {
impl_active_model_behavior: bool,

#[arg(
long,
default_value = "true",
long = "experimental-preserve-user-modifications",
alias = "preserve-user-modifications",
default_value = "false",
default_missing_value = "true",
num_args = 0..=1,
require_equals = true,
action = ArgAction::Set,
long_help = indoc::indoc! { "
Preserve user modifications when regenerating entity files.
Experimental!: Preserve user modifications when regenerating entity files.
Only supports:
- Extra derives and attributes of `Model` and `Relation`
- Impl blocks of `ActiveModelBehavior`"
- Impl blocks of `ActiveModelBehavior`
Deprecated alias: `--preserve-user-modifications`"
}
)]
preserve_user_modifications: bool,
Expand Down Expand Up @@ -407,13 +410,27 @@ pub enum BannerVersion {
Patch,
}

fn is_deprecated_preserve_user_modifications_flag(arg: &OsStr) -> bool {
arg.to_str()
.is_some_and(|arg| arg.starts_with("--preserve-user-modifications"))
}

/// Use this to build a local, version-controlled `sea-orm-cli` in dependent projects
/// (see [example use case](https://github.com/SeaQL/sea-orm/discussions/1889)).
#[cfg(feature = "codegen")]
pub async fn main() {
dotenv().ok();

let deprecated_preserve_user_modifications_flag_used = std::env::args_os()
.skip(1)
.any(|arg| is_deprecated_preserve_user_modifications_flag(&arg));

let cli = Cli::parse();
if deprecated_preserve_user_modifications_flag_used {
eprintln!(
"warning: `--preserve-user-modifications` is deprecated; use `--experimental-preserve-user-modifications` instead."
);
}
let verbose = cli.verbose;

match cli.command {
Expand Down
Loading