diff --git a/sea-orm-cli/src/commands.rs b/sea-orm-cli/src/commands.rs index dadb3ad2f..04a3d3b0b 100644 --- a/sea-orm-cli/src/commands.rs +++ b/sea-orm-cli/src/commands.rs @@ -3,6 +3,7 @@ use clap::ArgMatches; use regex::Regex; use sea_orm_codegen::{EntityTransformer, OutputFile, WithSerde}; use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command, str::FromStr}; +use tracing_subscriber::{prelude::*, EnvFilter}; use url::Url; pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box> { @@ -21,6 +22,17 @@ pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box String { + let mut info = String::new(); + let type_info = self.get_rs_type().to_string().replace(' ', ""); + let col_info = self.col_info(); + write!( + &mut info, + "Column `{}`: {}{}", + self.name, type_info, col_info + ) + .unwrap(); + info + } + + fn col_info(&self) -> String { + let mut info = String::new(); + if self.auto_increment { + write!(&mut info, ", auto_increment").unwrap(); + } + if self.not_null { + write!(&mut info, ", not_null").unwrap(); + } + if self.unique { + write!(&mut info, ", unique").unwrap(); + } + info + } } impl From for Column { @@ -361,6 +389,42 @@ mod tests { } } + #[test] + fn test_get_info() { + let column: Column = ColumnDef::new(Alias::new("id")).string().to_owned().into(); + assert_eq!(column.get_info().as_str(), "Column `id`: Option"); + + let column: Column = ColumnDef::new(Alias::new("id")) + .string() + .not_null() + .to_owned() + .into(); + assert_eq!(column.get_info().as_str(), "Column `id`: String, not_null"); + + let column: Column = ColumnDef::new(Alias::new("id")) + .string() + .not_null() + .unique_key() + .to_owned() + .into(); + assert_eq!( + column.get_info().as_str(), + "Column `id`: String, not_null, unique" + ); + + let column: Column = ColumnDef::new(Alias::new("id")) + .string() + .not_null() + .unique_key() + .auto_increment() + .to_owned() + .into(); + assert_eq!( + column.get_info().as_str(), + "Column `id`: String, auto_increment, not_null, unique" + ); + } + #[test] fn test_from_column_def() { let column: Column = ColumnDef::new(Alias::new("id")).string().to_owned().into(); diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 88d72ef32..922f4bced 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -4,6 +4,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use std::{collections::HashMap, str::FromStr}; use syn::{punctuated::Punctuated, token::Comma}; +use tracing::info; #[derive(Clone, Debug)] pub struct EntityWriter { @@ -94,6 +95,18 @@ impl EntityWriter { self.entities .iter() .map(|entity| { + let entity_file = format!("{}.rs", entity.get_table_name_snake_case()); + let column_info = entity + .columns + .iter() + .map(|column| column.get_info()) + .collect::>(); + + info!("Generating {}", entity_file); + for info in column_info.iter() { + info!(" > {}", info); + } + let mut lines = Vec::new(); Self::write_doc_comment(&mut lines); let code_blocks = if expanded_format { @@ -103,7 +116,7 @@ impl EntityWriter { }; Self::write(&mut lines, code_blocks); OutputFile { - name: format!("{}.rs", entity.get_table_name_snake_case()), + name: entity_file, content: lines.join("\n\n"), } })