Coder Social home page Coder Social logo

tortoise-cli's People

Contributors

long2ice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tortoise-cli's Issues

Its not finding the path ... see in settings.py my tortoise-conf is present but it saying module not found

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

generate schemas optionally

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)
  • with generate-schema param
$ tortoise-cli --generate-schema false -c settings.TORTOISE_ORM shell
  • without 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.

Read config from pyproject.toml (like aerich)

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.