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] Show progress when generating entity files #722

Closed
billy1624 opened this issue May 13, 2022 · 2 comments · Fixed by #735
Closed

[CLI] Show progress when generating entity files #722

billy1624 opened this issue May 13, 2022 · 2 comments · Fixed by #735
Labels
good first issue Good for newcomers
Milestone

Comments

@billy1624
Copy link
Member

Motivation

The sea-orm-cli generate entity command doesn't show its progress such as which entity (db table) it's generating. Some time when it fail, user have no idea which db table is at fault and making it hard to debug.

Proposed Solutions

  • Display the progress when running the command and show info such as the table name and the specification of table columns that it's currently generating

Additional Information

@kyoto7250
Copy link
Contributor

@billy1624

Hello, I am interested in this issue.
I am new comer to contributing to this repository, Could you tell me about it?

@tyt2y3 tyt2y3 added this to the 0.8.x milestone May 15, 2022
@billy1624 billy1624 added the good first issue Good for newcomers label May 16, 2022
@billy1624
Copy link
Member Author

Hey @kyoto7250, thanks for the interest!

I think there are two things we need to code.

First, log the table name and its column info of the generating entity.

  • We could add the tracing::info! macro to
    pub fn write_entities(&self, expanded_format: bool, with_serde: &WithSerde) -> Vec<OutputFile> {
    self.entities
    .iter()
    .map(|entity| {
    let mut lines = Vec::new();
    Self::write_doc_comment(&mut lines);
    let code_blocks = if expanded_format {
    Self::gen_expanded_code_blocks(entity, with_serde)
    } else {
    Self::gen_compact_code_blocks(entity, with_serde)
    };
    Self::write(&mut lines, code_blocks);
    OutputFile {
    name: format!("{}.rs", entity.get_table_name_snake_case()),
    content: lines.join("\n\n"),
    }
    })
    .collect()
    }
  • For example, in sea-orm-migration we have done something similar logging
    info!(
    "Dropping foreign key '{}' from table '{}'",
    constraint_name, table_name
    );

Second, print log of log level info via tracing_subscriber.

  • We could initialize the tracing_subscriber at the else part of
    if args.is_present("VERBOSE") {
    let _ = tracing_subscriber::fmt()
    .with_max_level(tracing::Level::DEBUG)
    .with_test_writer()
    .try_init();
    }
  • For example,
    } else {
    let fmt_layer = tracing_subscriber::fmt::layer()
    .with_target(false)
    .with_level(false)
    .without_time();
    tracing_subscriber::registry()
    .with(filter_layer)
    .with(fmt_layer)
    .init()
    };

@billy1624 billy1624 moved this to Triage in SeaQL Dev Tracker May 16, 2022
@billy1624 billy1624 moved this from Triage to Open for Contributions in SeaQL Dev Tracker May 16, 2022
kyoto7250 added a commit to kyoto7250/sea-orm that referenced this issue May 16, 2022
@billy1624 billy1624 moved this from Open for Contributions to In Progress in SeaQL Dev Tracker May 17, 2022
@billy1624 billy1624 moved this from In Progress to Review in SeaQL Dev Tracker May 19, 2022
tyt2y3 pushed a commit that referenced this issue Jun 12, 2022
* feat(sea-orm-cli): output lof about  generated file name.

#722

* include column names in info

* cargo fmt

* Update sea-orm-cli/src/commands.rs

Avoid multiple initializations

Co-authored-by: Billy Chan <[email protected]>

* show info per column

* refactor: use write! macro

* Refactoring

Co-authored-by: Billy Chan <[email protected]>
@billy1624 billy1624 moved this from Review to Done in SeaQL Dev Tracker Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants