Skip to content

Commit

Permalink
lint, DIPDUP_MIGRATIONS variable
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Jan 23, 2025
1 parent 8460083 commit ec53a32
Show file tree
Hide file tree
Showing 25 changed files with 15 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Releases prior to 7.0 has been removed from this file to declutter search result

### Changed

- env: Database migrations with aeric require `DIPDUP_MIGRATIONS` variable to be set.
- evm.etherscan: Datasource has been renamed from `abi.etherscan` to `evm.etherscan` for consistency.
- project: Expose Prometheus and internal API ports in default sqlite environment.

Expand Down
2 changes: 1 addition & 1 deletion docs/1.getting-started/5.database.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ For more information visit the official TimescaleDB documentation:
## Migrations

::banner{type="note"}
The database migrations feature is optional and is disabled by default. To enable it, you need to install `aerich`, which is available in the `[migrations]` optional dependencies group.
The database migrations feature is optional and is disabled by default. To enable it, you need to install `aerich`, which is available in the `[migrations]` optional dependencies group and set the `DIPDUP_MIGRATIONS` environment variable.
::

DipDup supports database migrations with [aerich](https://github.com/tortoise/aerich), a Tortoise ORM migration tool. The migration files are stored in the `migrations` directory in the project root.
Expand Down
1 change: 1 addition & 0 deletions docs/5.advanced/2.environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DipDup uses multiple environment variables internally. They read once on process
| `DIPDUP_DOCKER` | Running in Docker |
| `DIPDUP_JSON_LOG` | Log in JSON format |
| `DIPDUP_LOW_MEMORY` | Reduce the size of caches and buffers for low-memory environments (target is 256 MB) |
| `DIPDUP_MIGRATIONS` | Enable migrations with `aerich` |
| `DIPDUP_NEXT` | Enable experimental features from the next major release that require schema changes |
| `DIPDUP_NO_SYMLINK` | Don't create magic symlink in the package root even when used as cwd |
| `DIPDUP_NO_VERSION_CHECK` | Disable warning about running unstable or out-of-date DipDup version |
Expand Down
1 change: 0 additions & 1 deletion src/demo_blank/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_evm_events/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_evm_transactions/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_evm_uniswap/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_starknet_events/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_substrate_events/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_auction/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_dao/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_dex/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_domains/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_etherlink/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_events/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_factories/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_head/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_nft_marketplace/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_raw/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_token/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_token_balances/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
1 change: 0 additions & 1 deletion src/demo_tezos_token_transfers/handlers/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from dipdup.context import HandlerContext
from dipdup.index import MatchedHandler

Expand Down
8 changes: 7 additions & 1 deletion src/dipdup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,13 @@ async def hasura_configure(ctx: click.Context, force: bool) -> None:
@_cli_wrapper
async def schema(ctx: click.Context) -> None:
"""Commands to manage database schema."""
if '--help' in sys.argv or ctx.invoked_subcommand not in AERICH_CMDS:
if any(
(
'--help' in sys.argv,
ctx.invoked_subcommand not in AERICH_CMDS,
not env.MIGRATIONS,
)
):
return

config: DipDupConfig = ctx.obj.config
Expand Down
2 changes: 2 additions & 0 deletions src/dipdup/dipdup.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,8 @@ async def _initialize_migrations(self) -> None:
if isinstance(self._config.database, SqliteDatabaseConfig):
_logger.debug('SQLite database detected, skipping migrations initialization')
return
if not env.MIGRATIONS:
return

migrations_dir = self._ctx.package.migrations
try:
Expand Down
4 changes: 3 additions & 1 deletion src/dipdup/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ def get_path(key: str) -> Path | None:


def reload_env() -> None:
global CI, DEBUG, DOCKER, JSON_LOG, LOW_MEMORY, NEXT, NO_SYMLINK, NO_VERSION_CHECK, PACKAGE_PATH, REPLAY_PATH, TEST
global CI, DEBUG, DOCKER, JSON_LOG, LOW_MEMORY, MIGRATIONS, NEXT, NO_SYMLINK, NO_VERSION_CHECK, PACKAGE_PATH, REPLAY_PATH, TEST

CI = get_bool('DIPDUP_CI')
DEBUG = get_bool('DIPDUP_DEBUG')
DOCKER = get_bool('DIPDUP_DOCKER')
JSON_LOG = get_bool('DIPDUP_JSON_LOG')
LOW_MEMORY = get_bool('DIPDUP_LOW_MEMORY')
MIGRATIONS = get_bool('DIPDUP_MIGRATIONS')
NEXT = get_bool('DIPDUP_NEXT')
NO_SYMLINK = get_bool('DIPDUP_NO_SYMLINK')
NO_VERSION_CHECK = get_bool('DIPDUP_NO_VERSION_CHECK')
Expand All @@ -108,6 +109,7 @@ def set_test() -> None:
DOCKER: bool = get_bool('DIPDUP_DOCKER')
JSON_LOG: bool = get_bool('DIPDUP_JSON_LOG')
LOW_MEMORY: bool = get_bool('DIPDUP_LOW_MEMORY')
MIGRATIONS: bool = get_bool('DIPDUP_MIGRATIONS')
NEXT: bool = get_bool('DIPDUP_NEXT')
NO_SYMLINK: bool = get_bool('DIPDUP_NO_SYMLINK')
NO_VERSION_CHECK: bool = get_bool('DIPDUP_NO_VERSION_CHECK')
Expand Down

0 comments on commit ec53a32

Please sign in to comment.