def copy_mongodb( project: Optional[Project], source_db_name: str, destination_db_name: Optional[str], drop: bool, ): """ Copy an existing mongodb database. If no destination database is given defaults to the project mongodb database name. """ if not any([project, destination_db_name]): raise click.exceptions.MissingParameter( param_hint="destination_db_name", param_type="str", message= "Either specify a destination database name or run in a derex project.", ) if not destination_db_name and project: destination_db_name = project.mongodb_db_name if click.confirm( f'Copying database "{source_db_name}" to "{destination_db_name}."' "Are you sure you want to continue?"): from derex.runner.mongodb import copy_database copy_database(source_db_name, destination_db_name) if drop and click.confirm( f'Are you sure you want to drop database "{source_db_name}" ?' ): from derex.runner.mongodb import drop_database drop_database(source_db_name) return 0
def drop_mongodb(project: Optional[Project], db_name: str): """Drop a MongoDB database""" if not any([project, db_name]): raise click.exceptions.MissingParameter( param_hint="db_name", param_type="str", message= "Either specify a destination database name or run in a derex project.", ) if not db_name and project: db_name = project.mongodb_db_name if click.confirm( f'Dropping database "{db_name}". Are you sure you want to continue?' ): from derex.runner.mongodb import drop_database drop_database(db_name) return 0