Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

### 0.2.0

- feat: generate schemas optionally ([#7])
- Use `asyncclick` instead of `click` ([#6])
- Only install tomlkit for Python version less than 3.11 ([#5])
- Migrate lint tool from isort+black to ruff ([#5])
- Drop support for Python3.8 ([#4])

[#7]: https://github.com/tortoise/tortoise-cli/pull/7
[#6]: https://github.com/tortoise/tortoise-cli/pull/6
[#5]: https://github.com/tortoise/tortoise-cli/pull/5
[#4]: https://github.com/tortoise/tortoise-cli/pull/4
Expand Down
14 changes: 12 additions & 2 deletions tortoise_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,26 @@ async def aclose_tortoise() -> AsyncGenerator[None]:
"--config",
help="TortoiseORM config dictionary path, like settings.TORTOISE_ORM",
)
@click.option(
"--generate-schemas/--no-generate-schemas",
default=None,
help="Whether generate schemas after TortoiseORM inited",
)
@click.pass_context
async def cli(ctx: click.Context, config: str | None) -> None:
async def cli(ctx: click.Context, config: str | None, generate_schemas: bool | None = None):
if not config and not (config := utils.tortoise_orm_config()):
raise click.UsageError(
"You must specify TORTOISE_ORM in option or env, or config file pyproject.toml from config of aerich",
ctx=ctx,
)
tortoise_config = utils.get_tortoise_config(ctx, config)
await Tortoise.init(config=tortoise_config)
await Tortoise.generate_schemas(safe=True)
if generate_schemas is None:
cons = tortoise_config["connections"]
# Auto generate schemas when flag not explicitly passed and dialect is sqlite
generate_schemas = "sqlite" in str(cons.get("default", cons))
if generate_schemas:
await Tortoise.generate_schemas(safe=True)


@cli.command(help="Start a interactive shell.")
Expand Down