diff --git a/backend/geonature/core/command/create_gn_module.py b/backend/geonature/core/command/create_gn_module.py index 73a0aefbef..a74b42b2d1 100644 --- a/backend/geonature/core/command/create_gn_module.py +++ b/backend/geonature/core/command/create_gn_module.py @@ -23,11 +23,14 @@ @main.command() +@click.option( + "-x", "--x-arg", multiple=True, help="Additional arguments consumed by custom env.py scripts" +) @click.argument("module_path") @click.argument("module_code") @click.option("--build", type=bool, required=False, default=True) @click.option("--upgrade-db", type=bool, required=False, default=True) -def install_gn_module(module_path, module_code, build, upgrade_db): +def install_gn_module(x_arg, module_path, module_code, build, upgrade_db): click.echo("Installation du backend…") subprocess.run(f"pip install -e '{module_path}'", shell=True, check=True) @@ -66,13 +69,28 @@ def install_gn_module(module_path, module_code, build, upgrade_db): click.secho("Rebuild du frontend terminé.", fg="green") if upgrade_db: - click.echo("Installation de la basse de données…") - module_db_upgrade(module_dist) + click.echo("Installation de la base de données…") + module_db_upgrade(module_dist, x_arg=x_arg) @main.command() +@click.option( + "-d", + "--directory", + default=None, + help=('Migration script directory (default is "migrations")'), +) +@click.option( + "--sql", is_flag=True, help=("Don't emit SQL to database - dump to standard output " "instead") +) +@click.option( + "--tag", default=None, help=('Arbitrary "tag" name - can be used by custom env.py ' "scripts") +) +@click.option( + "-x", "--x-arg", multiple=True, help="Additional arguments consumed by custom env.py scripts" +) @click.argument("module_codes", metavar="[MODULE_CODE]...", nargs=-1) -def upgrade_modules_db(module_codes): +def upgrade_modules_db(directory, sql, tag, x_arg, module_codes): for module_code_entry in iter_entry_points("gn_module", "code"): module_code = module_code_entry.resolve() if module_codes and module_code not in module_codes: @@ -82,4 +100,4 @@ def upgrade_modules_db(module_codes): continue click.echo(f"Mise-à-jour du module {module_code}…") module_dist = module_code_entry.dist - module_db_upgrade(module_dist) + module_db_upgrade(module_dist, directory, sql, tag, x_arg) diff --git a/backend/geonature/utils/module.py b/backend/geonature/utils/module.py index c2324a82af..9876bc2d3c 100644 --- a/backend/geonature/utils/module.py +++ b/backend/geonature/utils/module.py @@ -42,7 +42,7 @@ def get_dist_from_code(module_code): raise Exception(f"Module with code {module_code} not installed in venv") -def module_db_upgrade(module_dist): +def module_db_upgrade(module_dist, directory=None, sql=False, tag=None, x_arg=[]): module_code = module_dist.load_entry_point("gn_module", "code") module = TModules.query.filter_by(module_code=module_code).one_or_none() if module is None: @@ -74,4 +74,5 @@ def module_db_upgrade(module_dist): alembic_branch = module_dist.load_entry_point("gn_module", "alembic_branch") except ImportError: alembic_branch = module_code.lower() - db_upgrade(revision=alembic_branch + "@head") + revision = alembic_branch + "@head" + db_upgrade(directory, revision, sql, tag, x_arg)