From 83c476a6738042e0ce35af07eb515d0a169c54ba Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 8 Nov 2022 13:15:53 +0300 Subject: CLI: Provide `apply-migrations` command for flask * main.py: Provide the `apply-migrations` CLI command to run the migrations against the auth database. The command can be invoked with: $ flask apply-migrations --- main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'main.py') diff --git a/main.py b/main.py index a587697..aaa51da 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,18 @@ from gn3.app import create_app app = create_app() +##### BEGIN: CLI Commands ##### + +@app.cli.command() +def apply_migrations(): + from yoyo import get_backend, read_migrations + from gn3.migrations import apply_migrations + apply_migrations( + get_backend(f'sqlite:///{app.config["AUTH_DB"]}'), + read_migrations(app.config["AUTH_MIGRATIONS"])) + +##### END: CLI Commands ##### + if __name__ == '__main__': print("Starting app...") app.run() -- cgit v1.2.3