@@ -153,25 +153,12 @@ def _get_revert_count(self, schema: str | None = None, table: str | None = None)
153153
154154 migration_list = []
155155 for cur_database , tables in table_by_database .items ():
156- external_tables = 0
157- managed_tables = 0
158- views = 0
156+ what_count : dict [What , int ] = {}
159157 for current_table in tables :
160158 if current_table .upgraded_to is not None :
161- if current_table .kind == "VIEW" :
162- views += 1
163- continue
164- if current_table .object_type == "EXTERNAL" :
165- external_tables += 1
166- continue
167- if current_table .object_type == "MANAGED" :
168- managed_tables += 1
169- continue
170- migration_list .append (
171- MigrationCount (
172- database = cur_database , managed_tables = managed_tables , external_tables = external_tables , views = views
173- )
174- )
159+ count = what_count .get (current_table .what , 0 )
160+ what_count [current_table .what ] = count + 1
161+ migration_list .append (MigrationCount (database = cur_database , what_count = what_count ))
175162 return migration_list
176163
177164 def is_upgraded (self , schema : str , table : str ) -> bool :
@@ -189,17 +176,36 @@ def print_revert_report(self, *, delete_managed: bool) -> bool | None:
189176 logger .info ("No migrated tables were found." )
190177 return False
191178 print ("The following is the count of migrated tables and views found in scope:" )
192- print ("Database | External Tables | Managed Table | Views |" )
193- print ("=" * 88 )
179+ table_header = "Database |"
180+ headers = 1
181+ for what in list (What ):
182+ headers = max (headers , len (what .name .split ("_" )))
183+ table_header += f" { what .name .split ('_' )[0 ]:<10} |"
184+ print (table_header )
185+ # Split the header so _ separated what names are splitted into multiple lines
186+ for header in range (1 , headers ):
187+ table_sub_header = " |"
188+ for what in list (What ):
189+ if len (what .name .split ("_" )) - 1 < header :
190+ table_sub_header += f"{ ' ' * 12 } |"
191+ continue
192+ table_sub_header += f" { what .name .split ('_' )[header ]:<10} |"
193+ print (table_sub_header )
194+ separator = "=" * (22 + 13 * len (What ))
195+ print (separator )
194196 for count in migrated_count :
195- print (f"{ count .database :<30} | { count .external_tables :16} | { count .managed_tables :16} | { count .views :16} |" )
196- print ("=" * 88 )
197- print ("Migrated External Tables and Views (targets) will be deleted" )
197+ table_row = f"{ count .database :<20} |"
198+ for what in list (What ):
199+ table_row += f" { count .what_count .get (what , 0 ):10} |"
200+ print (table_row )
201+ print (separator )
202+ print ("The following actions will be performed" )
203+ print ("- Migrated External Tables and Views (targets) will be deleted" )
198204 if delete_managed :
199- print ("Migrated Manged Tables (targets) will be deleted" )
205+ print ("- Migrated DBFS Root Tables will be deleted" )
200206 else :
201- print ("Migrated Manged Tables (targets) will be left intact. " )
202- print ("To revert and delete Migrated Tables, add --delete_managed true flag to the command. " )
207+ print ("- Migrated DBFS Root Tables will be left intact" )
208+ print ("To revert and delete Migrated Tables, add --delete_managed true flag to the command" )
203209 return True
204210
205211
0 commit comments