From 1bac33cd338e894eccfa5539700fe167add1e9bd Mon Sep 17 00:00:00 2001 From: long2ice Date: Fri, 30 Oct 2020 16:39:14 +0800 Subject: [PATCH] add confirmation_option when downgrade --- .DS_Store | Bin 0 -> 6148 bytes .vscode/settings.json | 4 ++++ aerich/cli.py | 12 ++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 .vscode/settings.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b786a6d52b027e1b0ad759618ac6454b1f7a3575 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8CKa&%p54(Su5xkYWQhDNSn88p(s`8+rG2 zoY~zLOBFnc*cq7pW@l%1*)L&dmodicgTQ92!Wc6^5ep_XUkHw)&PYLf5IN4_50jqX zjeY39%|w&qFEW7NuEYWsvV^6dzn|ahhDmB!@4QefEi5h>M!8&GDc`uAc<82HI!NkX z{|b9&UfS`seICc%iS79pVSCuDtR2Tu>V;9eFO$Qd4I$T;VHCu}dOV1NM9$-?0mCp& zvsu|3jkfI_Yqu(DH7l!%k!>C9SH<4JVV0T3`j&lk+PZsq96e>vFN#cgM+Y=` zeZ=t+A_~~}mOvC59gVp{7y;ob6;P#e{lwrZ9sEMaIT~|?DxGn;GR&h_=K6)gO&D?nSIC>WP3 loTPvuOEJV^Dc%5;0)Bx8prbKY2p$l+2uK>JAqIYxfe-%FQCa{1 literal 0 HcmV?d00001 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..32c4982 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.pythonPath": "venv/bin/python", + "python.formatting.provider": "black" +} \ No newline at end of file diff --git a/aerich/cli.py b/aerich/cli.py index eb14768..490af35 100644 --- a/aerich/cli.py +++ b/aerich/cli.py @@ -117,6 +117,11 @@ async def upgrade(ctx: Context): click.secho("No migrate items", fg=Color.yellow) +def abort_if_false(ctx, param, value): + if not value: + ctx.abort() + + @cli.command(help="Downgrade to specified version.") @click.option( "-v", @@ -127,6 +132,9 @@ async def upgrade(ctx: Context): help="Specified version, default to last.", ) @click.pass_context +@click.confirmation_option( + prompt="Downgrade is dangerous, which maybe lose your data, are you sure?", +) @coro async def downgrade(ctx: Context, version: int): app = ctx.obj["app"] @@ -191,7 +199,7 @@ async def history(ctx: Context): help="Tortoise-ORM config module dict variable, like settings.TORTOISE_ORM.", ) @click.option( - "--location", default="./migrations", show_default=True, help="Migrate store location." + "--location", default="./migrations", show_default=True, help="Migrate store location.", ) @click.pass_context @coro @@ -247,7 +255,7 @@ async def init_db(ctx: Context, safe): version = await Migrate.generate_version() await Aerich.create( - version=version, app=app, content=Migrate.get_models_content(config, app, location) + version=version, app=app, content=Migrate.get_models_content(config, app, location), ) with open(os.path.join(dirname, version), "w", encoding="utf-8") as f: content = {