Skip to content

Commit 2fa3ce8

Browse files
schema wipe confirmation, update hashes on schema approve and reason: ignore, update docs and help (#175)
* Update builtin logging configs * Docs, tiny optimization * Always update hashes on approval, schema wipe confirmation * Lint * Fix --immune argument
1 parent d41add8 commit 2fa3ce8

File tree

9 files changed

+131
-122
lines changed

9 files changed

+131
-122
lines changed

CHANGELOG.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
66

77
### ⚠ Migration
88

9-
* Run `dipdup schema approve --hashes` command on every database you want to use with 4.0.0-rc1.
9+
* Run `dipdup schema approve` command on every database you want to use with 4.0.0-rc1. Running `dipdup migrate` is not necessary since `spec_version` hasn't changed in this release.
1010

1111
### Added
1212

13-
* cli: Added `dipdup run --skip-hasura` flag to skip updating Hasura metadata.
14-
* cli: Added `dipdip run --early-realtime` flag to establish a realtime connection before all indexes are synchronized.
15-
* cli: Added`dipdup run --merge-subscriptions` flag to subscribe to all operations/big map diffs during realtime indexing. This flag helps to avoid reaching TzKT subscriptions limit (currently 10000 channels).
16-
* cli: Added `dipdup status` command to print the current status of indexes from database
17-
* cli: Added `dipdup config export [--unsafe]` command to print config after resolving all links and variables. Add `--unsafe` option to substitute environment variables.
18-
* cli: Added `dipdup cache show` command to get information about file caches used by DipDup.
19-
* cli: Added `dipdup schema approve --hashes` flag to recalculate schema and index config hashes on the next run.
13+
* cli: Added `run --skip-hasura` flag to skip updating Hasura metadata.
14+
* cli: Added `run --early-realtime` flag to establish a realtime connection before all indexes are synchronized.
15+
* cli: Added`run --merge-subscriptions` flag to subscribe to all operations/big map diffs during realtime indexing. This flag helps to avoid reaching TzKT subscriptions limit (currently 10000 channels).
16+
* cli: Added `status` command to print the current status of indexes from the database.
17+
* cli: Added `config export [--unsafe]` command to print config after resolving all links and variables. Add `--unsafe` option to substitute environment variables.
18+
* cli: Added `cache show` command to get information about file caches used by DipDup.
2019
* config: Added `first_level` and `last_level` optional fields to `TemplateIndexConfig`. These limits are applied after ones from the template itself.
2120
* config: Added `daemon` boolean field to `JobConfig` to run a single callback indefinitely. Conflicts with `crontab` and `interval` fields.
2221
* config: Added `advanced` top-level section with following fields:
@@ -36,11 +35,12 @@ advanced:
3635
skip_hasura: False
3736
```
3837
39-
`ReindexingRequiredError` exception raised by default when reindexing is triggered. CLI flags have priority over self-titled `AdvancedConfig` fields.
38+
`ReindexingRequiredError` exception is raised by default when reindexing is triggered. CLI flags have priority over self-titled `AdvancedConfig` fields.
4039

4140
### Fixed
4241

4342
* cli: Fixed crashes and output inconsistency when piping DipDup commands.
43+
* cli: Fixed `schema wipe --immune` flag being ignored.
4444
* codegen: Fixed missing imports in handlers generated during init.
4545
* coinbase: Fixed possible data inconsistency caused by caching enabled for method `get_candles`.
4646
* http: Fixed increasing sleep time between failed request attempts.
@@ -51,6 +51,12 @@ advanced:
5151
* tzkt: Fixed `get_originated_contracts` and `get_similar_contracts` methods whose output was limited to `HTTPConfig.batch_size` field.
5252
* tzkt: Fixed lots of SignalR bugs by replacing `aiosignalrcore` library with `pysignalr`.
5353

54+
## Changed
55+
56+
* cli: `dipdup schema wipe` command now requires confirmation when invoked in the interactive shell.
57+
* cli: `dipdup schema approve` command now also causes a recalculation of schema and index config hashes.
58+
* index: DipDup will recalculate respective hashes if reindexing is triggered with `config_modified: ignore` or `schema_modified: ignore` in advanced config.
59+
5460
### Deprecated
5561

5662
* cli: `run --oneshot` option is deprecated and will be removed in the next major release. The oneshot mode applies automatically when `last_level` field is set in the index config.
@@ -59,7 +65,7 @@ advanced:
5965
### Performance
6066

6167
* config: Configuration files are loaded 10x times faster.
62-
* index: Number of operations processed by matcher reduced by 40%-95% depending on number of addresses and entrypoints used.
68+
* index: Number of operations processed by matcher reduced by 40%-95% depending on the number of addresses and entrypoints used.
6369
* tzkt: Rate limit was increased. Try to set `connection_timeout` to a higher value if requests fail with `ConnectionTimeout` exception.
6470
* tzkt: Improved performance of response deserialization.
6571

src/dipdup/cli.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import signal
55
import subprocess
6+
import sys
67
from contextlib import suppress
78
from dataclasses import dataclass
89
from functools import wraps
@@ -341,26 +342,27 @@ async def schema(ctx):
341342
...
342343

343344

344-
@schema.command(name='approve', help='Continue indexing with the same schema after crashing with `ReindexingRequiredError`')
345-
@click.option('--hashes', is_flag=True, help='Recalculate hashes of schema and index configs saved in database')
345+
@schema.command(name='approve', help='Continue to use existing schema after reindexing was triggered')
346346
@click.pass_context
347347
@cli_wrapper
348348
async def schema_approve(ctx, hashes: bool):
349349
config: DipDupConfig = ctx.obj.config
350350
url = config.database.connection_string
351351
models = f'{config.package}.models'
352352

353+
_logger.info('Approving schema `%s`', url)
354+
353355
async with tortoise_wrapper(url, models):
354-
schema = await Schema.filter().get()
355-
if not schema.reindex:
356-
return
356+
# FIXME: Non-nullable fields
357+
await Schema.filter().update(
358+
reindex=None,
359+
hash='',
360+
)
361+
await Index.filter().update(
362+
config_hash='',
363+
)
357364

358-
schema.reindex = None # type: ignore
359-
if hashes:
360-
# FIXME: Non-nullable fields
361-
schema.hash = '' # type: ignore
362-
await Index.filter().update(config_hash='')
363-
await schema.save()
365+
_logger.info('Schema approved')
364366

365367

366368
@schema.command(name='wipe', help='Drop all database tables, functions and views')
@@ -372,13 +374,32 @@ async def schema_wipe(ctx, immune: bool):
372374
url = config.database.connection_string
373375
models = f'{config.package}.models'
374376

377+
try:
378+
assert sys.__stdin__.isatty()
379+
click.confirm(f'You\'re about to wipe schema `{url}`. All indexed data will be irreversibly lost, are you sure?', abort=True)
380+
except AssertionError:
381+
click.echo('Not in a TTY, skipping confirmation')
382+
# FIXME: Can't catch asyncio.CancelledError here
383+
except click.Abort:
384+
click.echo('Aborted')
385+
return
386+
387+
_logger.info('Wiping schema `%s`', url)
388+
375389
async with tortoise_wrapper(url, models):
376390
conn = get_connection(None)
377391
if isinstance(config.database, PostgresDatabaseConfig):
378-
await wipe_schema(conn, config.database.schema_name, config.database.immune_tables)
392+
await wipe_schema(
393+
conn=conn,
394+
name=config.database.schema_name,
395+
# NOTE: Don't be confused by the name of `--immune` flag, we want to drop all tables if it's set.
396+
immune_tables=config.database.immune_tables if not immune else (),
397+
)
379398
else:
380399
await Tortoise._drop_databases()
381400

401+
_logger.info('Schema wiped')
402+
382403

383404
@schema.command(name='export', help='Print schema SQL including `on_reindex` hook')
384405
@click.pass_context

src/dipdup/configs/debug.yml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
version: 1
2-
disable_existing_loggers: false
3-
formatters:
4-
brief:
5-
format: "%(levelname)-8s %(name)-20s %(message)s"
6-
handlers:
7-
console:
8-
level: DEBUG
9-
formatter: brief
10-
class: logging.StreamHandler
11-
stream : ext://sys.stdout
12-
loggers:
13-
dipdup:
14-
level: DEBUG
1+
version: 1
2+
disable_existing_loggers: false
3+
formatters:
4+
brief:
5+
format: "%(levelname)-8s %(name)-20s %(message)s"
6+
handlers:
7+
console:
8+
level: DEBUG
9+
formatter: brief
10+
class: logging.StreamHandler
11+
stream: ext://sys.stdout
12+
loggers:
13+
dipdup:
14+
level: DEBUG
1515

16-
SignalRCoreClient:
17-
formatter: brief
18-
aiosqlite:
19-
level: DEBUG
20-
db_client:
21-
level: DEBUG
22-
root:
16+
aiosqlite:
2317
level: DEBUG
24-
handlers:
25-
- console
18+
db_client:
19+
level: DEBUG
20+
root:
21+
level: DEBUG
22+
handlers:
23+
- console

src/dipdup/configs/logging.yml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
version: 1
2-
disable_existing_loggers: false
3-
formatters:
4-
brief:
5-
format: "%(levelname)-8s %(name)-20s %(message)s"
6-
handlers:
7-
console:
8-
level: INFO
9-
formatter: brief
10-
class: logging.StreamHandler
11-
stream : ext://sys.stdout
12-
loggers:
13-
dipdup:
14-
level: INFO
1+
version: 1
2+
disable_existing_loggers: false
3+
formatters:
4+
brief:
5+
format: "%(levelname)-8s %(name)-20s %(message)s"
6+
handlers:
7+
console:
8+
level: INFO
9+
formatter: brief
10+
class: logging.StreamHandler
11+
stream: ext://sys.stdout
12+
loggers:
13+
dipdup:
14+
level: INFO
1515

16-
SignalRCoreClient:
17-
formatter: brief
18-
aiosqlite:
19-
level: INFO
20-
db_client:
21-
level: INFO
22-
root:
16+
aiosqlite:
2317
level: INFO
24-
handlers:
25-
- console
18+
db_client:
19+
level: INFO
20+
root:
21+
level: INFO
22+
handlers:
23+
- console

src/dipdup/configs/warning.yml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
version: 1
2-
disable_existing_loggers: false
3-
formatters:
4-
brief:
5-
format: "%(levelname)-8s %(name)-20s %(message)s"
6-
handlers:
7-
console:
8-
level: WARNING
9-
formatter: brief
10-
class: logging.StreamHandler
11-
stream : ext://sys.stdout
12-
loggers:
13-
dipdup:
14-
level: WARNING
1+
version: 1
2+
disable_existing_loggers: false
3+
formatters:
4+
brief:
5+
format: "%(levelname)-8s %(name)-20s %(message)s"
6+
handlers:
7+
console:
8+
level: WARNING
9+
formatter: brief
10+
class: logging.StreamHandler
11+
stream: ext://sys.stdout
12+
loggers:
13+
dipdup:
14+
level: WARNING
1515

16-
SignalRCoreClient:
17-
formatter: brief
18-
aiosqlite:
19-
level: WARNING
20-
db_client:
21-
level: WARNING
22-
root:
16+
aiosqlite:
2317
level: WARNING
24-
handlers:
25-
- console
18+
db_client:
19+
level: WARNING
20+
root:
21+
level: WARNING
22+
handlers:
23+
- console

src/dipdup/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ async def reindex(self, reason: Optional[Union[str, ReindexingReason, Reindexing
118118
self.logger.warning('Reindexing initialized, reason: %s, action: %s', reason.value, action.value)
119119

120120
if action == ReindexingAction.ignore:
121+
if reason == ReindexingReasonC.schema_modified:
122+
await Schema.filter().update(hash='')
123+
elif reason == ReindexingReasonC.config_modified:
124+
await Index.filter().update(config_hash='')
121125
return
122126

123127
elif action == ReindexingAction.exception:

src/dipdup/datasources/bcd/datasource.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ def __init__(
3333
async def run(self) -> None:
3434
pass
3535

36-
async def resync(self) -> None:
37-
pass
38-
3936
async def get_tokens(self, address: str) -> List[Dict[str, Any]]:
4037
tokens, offset = [], 0
4138
while True:

0 commit comments

Comments
 (0)