From aa2eb604d4cb22d2277e8f227e235fc77c1f359a Mon Sep 17 00:00:00 2001 From: "Piotr F. Mieszkowski" Date: Wed, 21 Feb 2024 21:07:48 +0100 Subject: [PATCH] lacre.admin: Add a sub-command to manipulate database schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - It supports option '-i' to initialise the schema. - It logs a warning-level record of the schema manipulation. --- lacre/admin.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lacre/admin.py b/lacre/admin.py index 1b3c82a..fd2a9a0 100644 --- a/lacre/admin.py +++ b/lacre/admin.py @@ -29,6 +29,17 @@ def _no_database(): sys.exit(lacre.EX_CONFIG) +def sub_db(args): + """Sub-command to manipulate database.""" + LOG.debug('Database operations ahead') + + if args.init: + eng = repo.init_engine(conf.get_item('database', 'url')) + LOG.warning('Initialising database schema with engine: %s', eng) + print('Creating database tables') + db.create_tables(eng) + + def sub_queue(args): """Sub-command to inspect queue contents.""" LOG.debug('Inspecting queue...') @@ -111,6 +122,14 @@ def main(): sub_commands = parser.add_subparsers(help='Sub-commands', required=True) + cmd_db = sub_commands.add_parser('database', + help='', + aliases=['db'] + ) + cmd_db.add_argument('-i', '--init', action='store_true', + help='Initialise database schema') + cmd_db.set_defaults(operation=sub_db) + cmd_import = sub_commands.add_parser('import', help='Load identities from GnuPG directory to Lacre database' )