From c85db585fc54bed08922b6a6aaddcdf1313896aa Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Wed, 1 Mar 2023 23:55:42 +0100 Subject: [PATCH 1/3] add mara_db click group --- mara_db/__init__.py | 3 ++- mara_db/cli.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mara_db/__init__.py b/mara_db/__init__.py index c0e02e0..7c3b534 100644 --- a/mara_db/__init__.py +++ b/mara_db/__init__.py @@ -23,7 +23,8 @@ def MARA_ACL_RESOURCES(): def MARA_CLICK_COMMANDS(): from . import cli - return [cli.migrate] + return [cli.mara_db, + cli._migrate] def MARA_NAVIGATION_ENTRIES(): diff --git a/mara_db/cli.py b/mara_db/cli.py index b561589..7253787 100644 --- a/mara_db/cli.py +++ b/mara_db/cli.py @@ -1,14 +1,29 @@ """Auto-migrate command line interface""" +import click import sys +from warnings import warn -import click +@click.group() +def mara_db(): + """Commands to interact with the database.""" + pass -@click.command() + +@mara_db.command() def migrate(): """Compares the current database with all defined models and applies the diff""" import mara_db.auto_migration if not mara_db.auto_migration.auto_discover_models_and_migrate(): sys.exit(-1) + + +# Old cli commands to be dropped in 5.0: + +@click.command("migrate") +def _migrate(): + """Compares the current database with all defined models and applies the diff""" + warn("CLI command ` mara_db.migrate` will be dropped in 5.0. Please use: ` mara-db migrate`") + migrate.callback() From ea5d3ae0dc22df2423d981093b0614bad40a3e30 Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Thu, 2 Mar 2023 00:12:08 +0100 Subject: [PATCH 2/3] update docs --- docs/api.rst | 2 +- docs/cli.rst | 29 +++++++++++++++++++++++++++++ docs/index.rst | 13 ++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 docs/cli.rst diff --git a/docs/api.rst b/docs/api.rst index ec33d0a..630a6eb 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -3,7 +3,7 @@ API .. module:: mara_db -This part of the documentation covers all the interfaces of Mara Page. For +This part of the documentation covers all the interfaces of Mara DB. For parts where the package depends on external libraries, we document the most important right here and provide links to the canonical documentation. diff --git a/docs/cli.rst b/docs/cli.rst new file mode 100644 index 0000000..26f89c9 --- /dev/null +++ b/docs/cli.rst @@ -0,0 +1,29 @@ +CLI +=== + +.. module:: mara_db.cli + +The following +This part of the documentation covers all the available cli commands of Mara DB. + + +``migrate`` +----------- + +.. tabs:: + + .. group-tab:: Mara CLI + + .. code-block:: shell + + mara db migrate + + .. group-tab:: Mara Flask App + + .. code-block:: python + + flask mara-db migrate + + +Compares the current database db alias `mara` with all defined models and applies +the diff using alembic. diff --git a/docs/index.rst b/docs/index.rst index 1253d48..84adfad 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -59,6 +59,17 @@ This section focuses on the supported database engines. dbs/SQLite +CLI commands +------------ + +When you are looking at available CLI commands, here you are at the right place. + +.. toctree:: + :maxdepth: 2 + + cli + + API Reference ------------- @@ -80,4 +91,4 @@ Legal information and changelog are here for the interested. :maxdepth: 2 license - changes \ No newline at end of file + changes From 7d859152e7c23b8da8b058063684dd234f3ee53e Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Tue, 21 Nov 2023 11:49:05 +0100 Subject: [PATCH 3/3] typo --- docs/cli.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/cli.rst b/docs/cli.rst index 26f89c9..86fb1c5 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -3,7 +3,6 @@ CLI .. module:: mara_db.cli -The following This part of the documentation covers all the available cli commands of Mara DB.