55from datetime import datetime
66from typing import List , Optional , TypedDict
77
8- from tabulate import tabulate
98from typing_extensions import Literal
109
1110from pyneo4j_ogm .logger import logger
@@ -28,6 +27,30 @@ class MigrationStatus(TypedDict):
2827 status : Literal ["APPLIED" , "PENDING" ]
2928
3029
30+ def pretty_print (migrations : List [List [str ]]) -> None :
31+ """
32+ Prints a pretty version of the migration status.
33+
34+ migrations(List[List[str]]): A list of migrations where the first item is the migration
35+ name and the second item is the status.
36+ """
37+ max_length = max (len (str (item [0 ])) for item in migrations )
38+ top_border_line = "┌" + "─" * (max_length + 2 ) + "┬" + "─" * 26 + "┐"
39+ bottom_border_line = "└" + "─" * (max_length + 2 ) + "┴" + "─" * 26 + "┘"
40+ header_line = "│ " + "Migration" .ljust (max_length ) + " │ " + "Applied At" .ljust (24 ) + " │"
41+ separator_line = "├" + "─" * (max_length + 2 ) + "┼" + "─" * 26 + "┤"
42+
43+ print (top_border_line )
44+ print (header_line )
45+ print (separator_line )
46+
47+ for migration in migrations :
48+ row = "│ " + str (migration [0 ]).ljust (max_length ) + " │ " + str (migration [1 ]).ljust (24 ) + " │"
49+ print (row )
50+
51+ print (bottom_border_line )
52+
53+
3154async def status (config_path : Optional [str ] = None ) -> List [MigrationStatus ]:
3255 """
3356 Visualize the status of all migrations.
@@ -81,7 +104,7 @@ async def status(config_path: Optional[str] = None) -> List[MigrationStatus]:
81104
82105 logger .debug ("Sorting %s migrations by applied_at timestamp and name" , len (migrations ))
83106 migrations .sort (key = lambda migration : (migration [1 ], migration [0 ]))
84- print ( tabulate ( migrations , headers = [ "Migration" , "Applied at" ], tablefmt = "fancy_grid" ) )
107+ pretty_print ( migrations )
85108
86109 migration_status .sort (
87110 key = lambda migration : (migration ["applied_at" ] is None , migration ["applied_at" ], migration ["name" ])
0 commit comments