reformatted with black
This commit is contained in:
parent
8e783e031e
commit
185514f711
@ -48,7 +48,11 @@ def coro(f):
|
|||||||
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
|
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
|
||||||
@click.version_option(__version__, "-V", "--version")
|
@click.version_option(__version__, "-V", "--version")
|
||||||
@click.option(
|
@click.option(
|
||||||
"-c", "--config", default="aerich.ini", show_default=True, help="Config file.",
|
"-c",
|
||||||
|
"--config",
|
||||||
|
default="aerich.ini",
|
||||||
|
show_default=True,
|
||||||
|
help="Config file.",
|
||||||
)
|
)
|
||||||
@click.option("--app", required=False, help="Tortoise-ORM app name.")
|
@click.option("--app", required=False, help="Tortoise-ORM app name.")
|
||||||
@click.option(
|
@click.option(
|
||||||
@ -121,7 +125,9 @@ async def upgrade(ctx: Context):
|
|||||||
for upgrade_query in upgrade_query_list:
|
for upgrade_query in upgrade_query_list:
|
||||||
await conn.execute_script(upgrade_query)
|
await conn.execute_script(upgrade_query)
|
||||||
await Aerich.create(
|
await Aerich.create(
|
||||||
version=version_file, app=app, content=get_models_describe(app),
|
version=version_file,
|
||||||
|
app=app,
|
||||||
|
content=get_models_describe(app),
|
||||||
)
|
)
|
||||||
click.secho(f"Success upgrade {version_file}", fg=Color.green)
|
click.secho(f"Success upgrade {version_file}", fg=Color.green)
|
||||||
migrated = True
|
migrated = True
|
||||||
@ -215,17 +221,21 @@ async def history(ctx: Context):
|
|||||||
help="Tortoise-ORM config module dict variable, like settings.TORTOISE_ORM.",
|
help="Tortoise-ORM config module dict variable, like settings.TORTOISE_ORM.",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--location", default="./migrations", show_default=True, help="Migrate store location.",
|
"--location",
|
||||||
|
default="./migrations",
|
||||||
|
show_default=True,
|
||||||
|
help="Migrate store location.",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-s",
|
"-s",
|
||||||
"--src_folder", default=".", show_default=False, help="Folder of the source, relative to the project root."
|
"--src_folder",
|
||||||
|
default=".",
|
||||||
|
show_default=False,
|
||||||
|
help="Folder of the source, relative to the project root.",
|
||||||
)
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@coro
|
@coro
|
||||||
async def init(
|
async def init(ctx: Context, tortoise_orm, location, src_folder):
|
||||||
ctx: Context, tortoise_orm, location, src_folder
|
|
||||||
):
|
|
||||||
config_file = ctx.obj["config_file"]
|
config_file = ctx.obj["config_file"]
|
||||||
name = ctx.obj["name"]
|
name = ctx.obj["name"]
|
||||||
if Path(config_file).exists():
|
if Path(config_file).exists():
|
||||||
@ -234,8 +244,8 @@ async def init(
|
|||||||
if os.path.isabs(src_folder):
|
if os.path.isabs(src_folder):
|
||||||
src_folder = os.path.relpath(os.getcwd(), src_folder)
|
src_folder = os.path.relpath(os.getcwd(), src_folder)
|
||||||
# Add ./ so it's clear that this is relative path
|
# Add ./ so it's clear that this is relative path
|
||||||
if not src_folder.startswith('./'):
|
if not src_folder.startswith("./"):
|
||||||
src_folder = './' + src_folder
|
src_folder = "./" + src_folder
|
||||||
|
|
||||||
# check that we can find the configuration, if not we can fail before the config file gets created
|
# check that we can find the configuration, if not we can fail before the config file gets created
|
||||||
add_src_path(src_folder)
|
add_src_path(src_folder)
|
||||||
@ -287,7 +297,9 @@ async def init_db(ctx: Context, safe):
|
|||||||
|
|
||||||
version = await Migrate.generate_version()
|
version = await Migrate.generate_version()
|
||||||
await Aerich.create(
|
await Aerich.create(
|
||||||
version=version, app=app, content=get_models_describe(app),
|
version=version,
|
||||||
|
app=app,
|
||||||
|
content=get_models_describe(app),
|
||||||
)
|
)
|
||||||
content = {
|
content = {
|
||||||
"upgrade": [schema],
|
"upgrade": [schema],
|
||||||
@ -298,7 +310,11 @@ async def init_db(ctx: Context, safe):
|
|||||||
|
|
||||||
@cli.command(help="Introspects the database tables to standard output as TortoiseORM model.")
|
@cli.command(help="Introspects the database tables to standard output as TortoiseORM model.")
|
||||||
@click.option(
|
@click.option(
|
||||||
"-t", "--table", help="Which tables to inspect.", multiple=True, required=False,
|
"-t",
|
||||||
|
"--table",
|
||||||
|
help="Which tables to inspect.",
|
||||||
|
multiple=True,
|
||||||
|
required=False,
|
||||||
)
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@coro
|
@coro
|
||||||
|
@ -36,7 +36,8 @@ def get_app_connection_name(config, app_name: str) -> str:
|
|||||||
if app:
|
if app:
|
||||||
return app.get("default_connection", "default")
|
return app.get("default_connection", "default")
|
||||||
raise BadOptionUsage(
|
raise BadOptionUsage(
|
||||||
option_name="--app", message=f'Can\'t get app named "{app_name}"',
|
option_name="--app",
|
||||||
|
message=f'Can\'t get app named "{app_name}"',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ def get_tortoise_config(ctx: Context, tortoise_orm: str) -> dict:
|
|||||||
try:
|
try:
|
||||||
config_module = importlib.import_module(config_path)
|
config_module = importlib.import_module(config_path)
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
raise ClickException(f'Error while importing configuration module: {e}') from None
|
raise ClickException(f"Error while importing configuration module: {e}") from None
|
||||||
|
|
||||||
config = getattr(config_module, tortoise_config, None)
|
config = getattr(config_module, tortoise_config, None)
|
||||||
if not config:
|
if not config:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user