Пример #1
0
async def cli(ctx: Context, config, app, name):
    ctx.ensure_object(dict)
    ctx.obj["config_file"] = config
    ctx.obj["name"] = name
    ctx.obj["app"] = app

    invoked_subcommand = ctx.invoked_subcommand
    if invoked_subcommand != "init":
        if not os.path.exists(config):
            raise UsageError("You must exec init first", ctx=ctx)
        parser.read(config)

        location = parser[name]["location"]
        tortoise_orm = parser[name]["tortoise_orm"]

        tortoise_config = get_tortoise_config(ctx, tortoise_orm)

        ctx.obj["config"] = tortoise_config
        ctx.obj["location"] = location

        if invoked_subcommand != "init-db":
            try:
                await Migrate.init_with_old_models(tortoise_config, app, location)
            except ConfigurationError:
                raise UsageError(ctx=ctx, message="You must exec init-db first")
Пример #2
0
async def cli(ctx: Context, config, app, name):
    ctx.ensure_object(dict)
    ctx.obj["config_file"] = config
    ctx.obj["name"] = name

    invoked_subcommand = ctx.invoked_subcommand
    if invoked_subcommand != "init":
        if not os.path.exists(config):
            raise UsageError("You must exec init first", ctx=ctx)
        parser.read(config)

        location = parser[name]["location"]
        tortoise_orm = parser[name]["tortoise_orm"]

        tortoise_config = get_tortoise_config(ctx, tortoise_orm)
        app = app or list(tortoise_config.get("apps").keys())[0]
        if "aerich.models" not in tortoise_config.get("apps").get(app).get(
                "models"):
            raise UsageError(
                "Check your tortoise config and add aerich.models to it.",
                ctx=ctx)
        ctx.obj["config"] = tortoise_config
        ctx.obj["location"] = location
        ctx.obj["app"] = app

        if invoked_subcommand != "init-db":
            await Migrate.init_with_old_models(tortoise_config, app, location)