From b63c2c2d121022d83650ea53d2d269dbda2e7c5a Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Mon, 11 Mar 2024 21:24:57 -0400 Subject: [PATCH] dbutils: add autocreate option to revision --- core/data/database.py | 12 ++++++++++++ dbutils.py | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/data/database.py b/core/data/database.py index 2bcd509..cb60886 100644 --- a/core/data/database.py +++ b/core/data/database.py @@ -235,3 +235,15 @@ class Data: "-m", message, ) + + async def create_revision_auto(self, message: str) -> None: + if not message: + self.logger.info("Message is required for create-revision") + return + + self.__alembic_cmd( + "revision", + "--autogenerate", + "-m", + message, + ) diff --git a/dbutils.py b/dbutils.py index 17a0bea..955e509 100644 --- a/dbutils.py +++ b/dbutils.py @@ -22,7 +22,7 @@ if __name__ == "__main__": parser.add_argument("--email", "-e", type=str, help="Email for the new user") parser.add_argument("--access_code", "-a", type=str, help="Access code for new/transfer user", default="00000000000000000000") parser.add_argument("--message", "-m", type=str, help="Revision message") - parser.add_argument("action", type=str, help="create, upgrade, create-owner, migrate, create-revision") + parser.add_argument("action", type=str, help="create, upgrade, downgrade, create-owner, migrate, create-revision, create-autorevision") args = parser.parse_args() cfg = CoreConfig() @@ -66,5 +66,9 @@ if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(data.create_revision(args.message)) + elif args.action == "create-autorevision": + loop = asyncio.get_event_loop() + loop.run_until_complete(data.create_revision_auto(args.message)) + else: logging.getLogger("database").info(f"Unknown action {args.action}")