tortoise / tortoise-cli Goto Github PK
View Code? Open in Web Editor NEWA cli tool for tortoise-orm, build on top of click and ptpython
License: Apache License 2.0
A cli tool for tortoise-orm, build on top of click and ptpython
License: Apache License 2.0
Error: Error while importing configuration module: No module named 'settings'
root@4288e7c9f646:/app# tortoise-cli -c settings.TORTOISE_ORM shell
Error: Error while importing configuration module: No module named 'settings'
root@4288e7c9f646:/app# ls
DockerProdFile init.py aerich.ini docker-compose.yaml main.py pip settings.py static
Dockerfile pycache commands.txt env migrations requirements.txt src tortoise-cli
Hello, thank you for your work on this. I've been using your project very helpfully.
I have one feature request : generate schemas optionally.
I'm using a db user that does not have permission to execute DDL for tortoise-orm and executing shell command configured with the user occurs OperationalError.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/dapi-venv/bin/tortoise-cli", line 8, in <module>
sys.exit(main())
File "/dapi-venv/lib/python3.9/site-packages/tortoise_cli/cli.py", line 76, in main
cli()
File "/dapi-venv/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/dapi-venv/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/dapi-venv/lib/python3.9/site-packages/click/core.py", line 1654, in invoke
super().invoke(ctx)
File "/dapi-venv/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/dapi-venv/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/dapi-venv/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/dapi-venv/lib/python3.9/site-packages/tortoise_cli/cli.py", line 21, in wrapper
loop.run_until_complete(f(*args, **kwargs))
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/dapi-venv/lib/python3.9/site-packages/tortoise_cli/cli.py", line 55, in cli
await Tortoise.generate_schemas(safe=True)
File "/dapi-venv/lib/python3.9/site-packages/tortoise/__init__.py", line 662, in generate_schemas
await generate_schema_for_client(connection, safe)
File "/dapi-venv/lib/python3.9/site-packages/tortoise/utils.py", line 31, in generate_schema_for_client
await generator.generate_from_string(schema)
File "/dapi-venv/lib/python3.9/site-packages/tortoise/backends/base/schema_generator.py", line 448, in generate_from_string
await self.client.execute_script(creation_string)
File "/dapi-venv/lib/python3.9/site-packages/tortoise/backends/mysql/client.py", line 52, in translate_exceptions_
raise OperationalError(exc)
tortoise.exceptions.OperationalError: (1142, "CREATE command denied to user 'user_rw'@'10.240.35.55' for table 'city'")
So I think the command will be more useful if it allows to generate schema optionally like below.
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
@click.version_option(__version__, "-V", "--version")
@click.option(
"-c",
"--config",
help="TortoiseORM config dictionary path, like settings.TORTOISE_ORM",
)
@click.option(
"--generate-schema",
show_default=True,
default=True,
help="Generate database schema.",
)
@click.pass_context
@coro
async def cli(ctx: click.Context, config: Optional[str], generate_schema: bool):
...
if generate_schema:
print("generate schema automatically..")
tortoise_config = utils.get_tortoise_config(ctx, config)
await Tortoise.init(config=tortoise_config)
await Tortoise.generate_schemas(safe=True)
generate-schema
param$ tortoise-cli --generate-schema false -c settings.TORTOISE_ORM shell
generate-schema
param (generate schemas by default)$ tortoise-cli -c settings.TORTOISE_ORM shell
I'll be appreciated if you consider my request and give me an opportunity to create PR for this.
This is a really helpful project. Thank you for your work on this.
I have one feature request: Also provide option to read tortoise orm config from the pyproject.toml
file like aerich.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.