11use anyhow:: Result ;
2+ use colored:: Colorize ;
23use vespertide_planner:: plan_next_migration;
34
45use crate :: utils:: { load_config, load_migrations, load_models} ;
@@ -13,13 +14,26 @@ pub fn cmd_diff() -> Result<()> {
1314 . map_err ( |e| anyhow:: anyhow!( "planning error: {}" , e) ) ?;
1415
1516 if plan. actions . is_empty ( ) {
16- println ! ( "No differences found. Schema is up to date." ) ;
17+ println ! (
18+ "{} {}" ,
19+ "No differences found." . bright_green( ) ,
20+ "Schema is up to date." . bright_white( )
21+ ) ;
1722 } else {
18- println ! ( "Found {} change(s) to apply:" , plan. actions. len( ) ) ;
23+ println ! (
24+ "{} {} {}" ,
25+ "Found" . bright_cyan( ) ,
26+ plan. actions. len( ) . to_string( ) . bright_yellow( ) . bold( ) ,
27+ "change(s) to apply:" . bright_cyan( )
28+ ) ;
1929 println ! ( ) ;
2030
2131 for ( i, action) in plan. actions . iter ( ) . enumerate ( ) {
22- println ! ( "{}. {}" , i + 1 , format_action( action) ) ;
32+ println ! (
33+ "{}. {}" ,
34+ ( i + 1 ) . to_string( ) . bright_magenta( ) . bold( ) ,
35+ format_action( action)
36+ ) ;
2337 }
2438 }
2539 Ok ( ( ) )
@@ -28,38 +42,87 @@ pub fn cmd_diff() -> Result<()> {
2842fn format_action ( action : & MigrationAction ) -> String {
2943 match action {
3044 MigrationAction :: CreateTable { table, .. } => {
31- format ! ( "Create table: {}" , table)
45+ format ! (
46+ "{} {}" ,
47+ "Create table:" . bright_green( ) ,
48+ table. bright_cyan( ) . bold( )
49+ )
3250 }
3351 MigrationAction :: DeleteTable { table } => {
34- format ! ( "Delete table: {}" , table)
52+ format ! (
53+ "{} {}" ,
54+ "Delete table:" . bright_red( ) ,
55+ table. bright_cyan( ) . bold( )
56+ )
3557 }
3658 MigrationAction :: AddColumn { table, column, .. } => {
37- format ! ( "Add column: {}.{}" , table, column. name)
59+ format ! (
60+ "{} {}.{}" ,
61+ "Add column:" . bright_green( ) ,
62+ table. bright_cyan( ) ,
63+ column. name. bright_cyan( ) . bold( )
64+ )
3865 }
3966 MigrationAction :: RenameColumn { table, from, to } => {
40- format ! ( "Rename column: {}.{} -> {}" , table, from, to)
67+ format ! (
68+ "{} {}.{} {} {}" ,
69+ "Rename column:" . bright_yellow( ) ,
70+ table. bright_cyan( ) ,
71+ from. bright_white( ) ,
72+ "->" . bright_white( ) ,
73+ to. bright_cyan( ) . bold( )
74+ )
4175 }
4276 MigrationAction :: DeleteColumn { table, column } => {
43- format ! ( "Delete column: {}.{}" , table, column)
77+ format ! (
78+ "{} {}.{}" ,
79+ "Delete column:" . bright_red( ) ,
80+ table. bright_cyan( ) ,
81+ column. bright_cyan( ) . bold( )
82+ )
4483 }
4584 MigrationAction :: ModifyColumnType { table, column, .. } => {
46- format ! ( "Modify column type: {}.{}" , table, column)
85+ format ! (
86+ "{} {}.{}" ,
87+ "Modify column type:" . bright_yellow( ) ,
88+ table. bright_cyan( ) ,
89+ column. bright_cyan( ) . bold( )
90+ )
4791 }
4892 MigrationAction :: AddIndex { table, index } => {
49- format ! ( "Add index: {} on {}" , index. name, table)
93+ format ! (
94+ "{} {} {} {}" ,
95+ "Add index:" . bright_green( ) ,
96+ index. name. bright_cyan( ) . bold( ) ,
97+ "on" . bright_white( ) ,
98+ table. bright_cyan( )
99+ )
50100 }
51101 MigrationAction :: RemoveIndex { table, name } => {
52- format ! ( "Remove index: {} from {}" , name, table)
102+ format ! (
103+ "{} {} {} {}" ,
104+ "Remove index:" . bright_red( ) ,
105+ name. bright_cyan( ) . bold( ) ,
106+ "from" . bright_white( ) ,
107+ table. bright_cyan( )
108+ )
53109 }
54110 MigrationAction :: RenameTable { from, to } => {
55- format ! ( "Rename table: {} -> {}" , from, to)
111+ format ! (
112+ "{} {} {} {}" ,
113+ "Rename table:" . bright_yellow( ) ,
114+ from. bright_cyan( ) ,
115+ "->" . bright_white( ) ,
116+ to. bright_cyan( ) . bold( )
117+ )
56118 }
57119 }
58120}
59121
60122#[ cfg( test) ]
61123mod tests {
62124 use super :: * ;
125+ use colored:: Colorize ;
63126 use rstest:: rstest;
64127 use serial_test:: serial;
65128 use std:: fs;
@@ -113,11 +176,11 @@ mod tests {
113176 #[ rstest]
114177 #[ case(
115178 MigrationAction :: CreateTable { table: "users" . into( ) , columns: vec![ ] , constraints: vec![ ] } ,
116- " Create table: users"
179+ format! ( "{} {}" , " Create table:" . bright_green ( ) , " users". bright_cyan ( ) . bold ( ) )
117180 ) ]
118181 #[ case(
119182 MigrationAction :: DeleteTable { table: "users" . into( ) } ,
120- " Delete table: users"
183+ format! ( "{} {}" , " Delete table:" . bright_red ( ) , " users". bright_cyan ( ) . bold ( ) )
121184 ) ]
122185 #[ case(
123186 MigrationAction :: AddColumn {
@@ -130,27 +193,27 @@ mod tests {
130193 } ,
131194 fill_with: None ,
132195 } ,
133- " Add column: users. name"
196+ format! ( "{} {}.{}" , " Add column:" . bright_green ( ) , " users" . bright_cyan ( ) , " name". bright_cyan ( ) . bold ( ) )
134197 ) ]
135198 #[ case(
136199 MigrationAction :: RenameColumn {
137200 table: "users" . into( ) ,
138201 from: "old" . into( ) ,
139202 to: "new" . into( ) ,
140203 } ,
141- " Rename column: users. old -> new"
204+ format! ( "{} {}.{} {} {}" , " Rename column:" . bright_yellow ( ) , " users" . bright_cyan ( ) , " old" . bright_white ( ) , "->" . bright_white ( ) , " new". bright_cyan ( ) . bold ( ) )
142205 ) ]
143206 #[ case(
144207 MigrationAction :: DeleteColumn { table: "users" . into( ) , column: "name" . into( ) } ,
145- " Delete column: users. name"
208+ format! ( "{} {}.{}" , " Delete column:" . bright_red ( ) , " users" . bright_cyan ( ) , " name". bright_cyan ( ) . bold ( ) )
146209 ) ]
147210 #[ case(
148211 MigrationAction :: ModifyColumnType {
149212 table: "users" . into( ) ,
150213 column: "id" . into( ) ,
151214 new_type: ColumnType :: Integer ,
152215 } ,
153- " Modify column type: users. id"
216+ format! ( "{} {}.{}" , " Modify column type:" . bright_yellow ( ) , " users" . bright_cyan ( ) , " id". bright_cyan ( ) . bold ( ) )
154217 ) ]
155218 #[ case(
156219 MigrationAction :: AddIndex {
@@ -161,18 +224,18 @@ mod tests {
161224 unique: false ,
162225 } ,
163226 } ,
164- " Add index: idx on users"
227+ format! ( "{} {} {} {}" , " Add index:" . bright_green ( ) , " idx" . bright_cyan ( ) . bold ( ) , "on" . bright_white ( ) , " users". bright_cyan ( ) )
165228 ) ]
166229 #[ case(
167230 MigrationAction :: RemoveIndex { table: "users" . into( ) , name: "idx" . into( ) } ,
168- " Remove index: idx from users"
231+ format! ( "{} {} {} {}" , " Remove index:" . bright_red ( ) , " idx" . bright_cyan ( ) . bold ( ) , " from" . bright_white ( ) , " users". bright_cyan ( ) )
169232 ) ]
170233 #[ case(
171234 MigrationAction :: RenameTable { from: "users" . into( ) , to: "accounts" . into( ) } ,
172- " Rename table: users -> accounts"
235+ format! ( "{} {} {} {}" , " Rename table:" . bright_yellow ( ) , " users" . bright_cyan ( ) , "->" . bright_white ( ) , " accounts". bright_cyan ( ) . bold ( ) )
173236 ) ]
174237 #[ serial]
175- fn format_action_cases ( #[ case] action : MigrationAction , #[ case] expected : & str ) {
238+ fn format_action_cases ( #[ case] action : MigrationAction , #[ case] expected : String ) {
176239 assert_eq ! ( format_action( & action) , expected) ;
177240 }
178241
0 commit comments