-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't add aerich.models to tortoise_config if migrations is disabled (#…
- Loading branch information
Showing
4 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +0,0 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Iterable | ||
from pathlib import Path | ||
from types import ModuleType | ||
|
||
from aerich import Command as AerichCommand # type: ignore[import-untyped] | ||
|
||
|
||
async def create_aerich_command(db_url: str, package: str, migrations_dir: 'Path') -> 'AerichCommand': | ||
"""Create and return an `AerichCommand` instance | ||
The AerichCommand is the entry point to manage database migrations using aerich. | ||
""" | ||
from aerich import Command as AerichCommand | ||
from tortoise.backends.base.config_generator import generate_config | ||
|
||
# TODO: Refactor building the app_modules dict and use here and in the tortoise_wrapper function ? | ||
# Or maybe add the tortoise_config to database config ? | ||
app_modules: dict[str, Iterable[str | ModuleType]] = {'models': [f'{package}.models', 'aerich.models']} | ||
tortoise_config = generate_config(db_url=db_url, app_modules=app_modules) | ||
return AerichCommand(tortoise_config=tortoise_config, app='models', location=migrations_dir.as_posix()) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters