Fix empty items

This commit is contained in:
long2ice 2020-11-30 11:14:09 +08:00
parent 4e917495a0
commit ee6cc20c7d
2 changed files with 7 additions and 3 deletions

View File

@ -125,7 +125,7 @@ async def upgrade(ctx: Context):
click.secho(f"Success upgrade {version_file}", fg=Color.green)
migrated = True
if not migrated:
click.secho("No items to be migrated", fg=Color.yellow)
click.secho("No upgrade items found", fg=Color.yellow)
@cli.command(help="Downgrade to specified version.")
@ -170,7 +170,8 @@ async def downgrade(ctx: Context, version: int, delete: bool):
content = get_version_content_from_file(file_path)
downgrade_query_list = content.get("downgrade")
if not downgrade_query_list:
return click.secho("No downgrade items found", fg=Color.yellow)
click.secho("No downgrade items found", fg=Color.yellow)
return
for downgrade_query in downgrade_query_list:
await conn.execute_query(downgrade_query)
await version.delete()

View File

@ -71,7 +71,10 @@ def get_version_content_from_file(version_file: str) -> Dict:
second = len(content) - 1
upgrade_content = content[first + len(_UPGRADE) : second].strip() # noqa:E203
downgrade_content = content[second + len(_DOWNGRADE) :].strip() # noqa:E203
ret = {"upgrade": upgrade_content.split(";\n"), "downgrade": downgrade_content.split(";\n")}
ret = {
"upgrade": list(filter(lambda x: x or False, upgrade_content.split(";\n"))),
"downgrade": list(filter(lambda x: x or False, downgrade_content.split(";\n"))),
}
return ret