From c4deff9d1c64dc2b2275c67ced64767ac848e852 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Mon, 4 Mar 2024 00:50:51 -0500 Subject: [PATCH] add database downgrading --- core/data/database.py | 8 +++++++- dbutils.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/data/database.py b/core/data/database.py index 83863a8..2bcd509 100644 --- a/core/data/database.py +++ b/core/data/database.py @@ -118,7 +118,13 @@ class Data: def schema_upgrade(self, ver: str = None): self.__alembic_cmd( "upgrade", - "head", + "head" if not ver else ver, + ) + + def schema_downgrade(self, ver: str): + self.__alembic_cmd( + "downgrade", + ver, ) async def create_owner(self, email: Optional[str] = None, code: Optional[str] = "00000000000000000000") -> None: diff --git a/dbutils.py b/dbutils.py index e5ea065..17a0bea 100644 --- a/dbutils.py +++ b/dbutils.py @@ -48,6 +48,12 @@ if __name__ == "__main__": elif args.action == "upgrade": data.schema_upgrade(args.version) + elif args.action == "downgrade": + if not args.version: + logging.getLogger("database").error(f"Version argument required for downgrade") + exit(1) + data.schema_downgrade(args.version) + elif args.action == "create-owner": loop = asyncio.get_event_loop() loop.run_until_complete(data.create_owner(args.email, args.access_code))