Skip to content

Commit

Permalink
add mara_db click group (#74)
Browse files Browse the repository at this point in the history
* add mara_db click group

* update docs

* typo
  • Loading branch information
leo-schick authored Nov 21, 2023
1 parent ae69f7b commit 3ea3111
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
28 changes: 28 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CLI
===

.. module:: mara_db.cli

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.
11 changes: 11 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------

Expand Down
3 changes: 2 additions & 1 deletion mara_db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
19 changes: 17 additions & 2 deletions mara_db/cli.py
Original file line number Diff line number Diff line change
@@ -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 `<app> mara_db.migrate` will be dropped in 5.0. Please use: `<app> mara-db migrate`")
migrate.callback()

0 comments on commit 3ea3111

Please sign in to comment.