async def init_db(ctx: Context, safe): config = ctx.obj["config"] location = ctx.obj["location"] app = ctx.obj["app"] dirname = Path(location, app) try: dirname.mkdir(parents=True) click.secho(f"Success create app migrate location {dirname}", fg=Color.green) except FileExistsError: return click.secho( f"Inited {app} already, or delete {dirname} and try again.", fg=Color.yellow) await Tortoise.init(config=config) connection = get_app_connection(config, app) await generate_schema_for_client(connection, safe) schema = get_schema_sql(connection, safe) version = await Migrate.generate_version() await Aerich.create( version=version, app=app, content=get_models_describe(app), ) content = { "upgrade": [schema], } write_version_file(Path(dirname, version), content) click.secho(f'Success generate schema for app "{app}"', fg=Color.green)
async def _generate_diff_sql(cls, name): version = await cls.generate_version(name) # delete if same version exists for version_file in cls.get_all_version_files(): if version_file.startswith(version.split("_")[0]): os.unlink(Path(cls.migrate_location, version_file)) content = { "upgrade": cls.upgrade_operators, "downgrade": cls.downgrade_operators, } write_version_file(Path(cls.migrate_location, version), content) return version
async def init_db(self, safe: bool): location = self.location app = self.app dirname = Path(location, app) dirname.mkdir(parents=True) await Tortoise.init(config=self.tortoise_config) connection = get_app_connection(self.tortoise_config, app) await generate_schema_for_client(connection, safe) schema = get_schema_sql(connection, safe) version = await Migrate.generate_version() await Aerich.create( version=version, app=app, content=get_models_describe(app), ) content = { "upgrade": [schema], } write_version_file(Path(dirname, version), content)