Skip to content

Commit 5067bf2

Browse files
schema wipe --force argument (#221)
* `schema wipe --force` argument * Pretty warnings
1 parent 8ddc980 commit 5067bf2

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
44

55
## [unreleased]
66

7+
### Added
8+
9+
* cli: Added `schema wipe --force` argument to skip confirmation promt.
10+
711
### Fixed
812

13+
* cli: Show warning about deprecated `--hashes` argument
914
* cli: Ignore `SIGINT` signal when shutdown is in progress.
1015
* sentry: Ignore exceptions when shutdown is in progress.
1116

src/dipdup/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import logging
12
import os
23
import sys
4+
import warnings
35

46
__version__ = '4.1.1'
57
__spec_version__ = '1.2'
@@ -17,3 +19,6 @@
1719
}
1820

1921
sys.path.append(os.getcwd())
22+
logging.captureWarnings(True)
23+
warnings.simplefilter('always', DeprecationWarning)
24+
warnings.formatwarning = lambda msg, *a, **kw: str(msg)

src/dipdup/cli.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import signal
66
import subprocess
77
import sys
8+
import warnings
89
from contextlib import AsyncExitStack
910
from contextlib import suppress
1011
from dataclasses import dataclass
@@ -350,6 +351,9 @@ async def schema(ctx):
350351
@click.pass_context
351352
@cli_wrapper
352353
async def schema_approve(ctx, hashes: bool):
354+
if hashes:
355+
warnings.warn('`--hashes` option is deprecated and has no effect', DeprecationWarning)
356+
353357
config: DipDupConfig = ctx.obj.config
354358
url = config.database.connection_string
355359
models = f'{config.package}.models'
@@ -371,22 +375,24 @@ async def schema_approve(ctx, hashes: bool):
371375

372376
@schema.command(name='wipe', help='Drop all database tables, functions and views')
373377
@click.option('--immune', is_flag=True, help='Drop immune tables too')
378+
@click.option('--force', is_flag=True, help='Skip confirmation prompt')
374379
@click.pass_context
375380
@cli_wrapper
376-
async def schema_wipe(ctx, immune: bool):
381+
async def schema_wipe(ctx, immune: bool, force: bool):
377382
config: DipDupConfig = ctx.obj.config
378383
url = config.database.connection_string
379384
models = f'{config.package}.models'
380385

381-
try:
382-
assert sys.__stdin__.isatty()
383-
click.confirm(f'You\'re about to wipe schema `{url}`. All indexed data will be irreversibly lost, are you sure?', abort=True)
384-
except AssertionError:
385-
click.echo('Not in a TTY, skipping confirmation')
386-
# FIXME: Can't catch asyncio.CancelledError here
387-
except click.Abort:
388-
click.echo('Aborted')
389-
return
386+
if not force:
387+
try:
388+
assert sys.__stdin__.isatty()
389+
click.confirm(f'You\'re about to wipe schema `{url}`. All indexed data will be irreversibly lost, are you sure?', abort=True)
390+
except AssertionError:
391+
click.echo('Not in a TTY, skipping confirmation')
392+
# FIXME: Can't catch asyncio.CancelledError here
393+
except click.Abort:
394+
click.echo('Aborted')
395+
return
390396

391397
_logger.info('Wiping schema `%s`', url)
392398

0 commit comments

Comments
 (0)