From 22faaa9bbc1651d9d548ea48603b8e6a2933e079 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 1 Sep 2023 00:24:47 -0400 Subject: [PATCH] [Bookworm] Correct Flask DB migration process Move the old manage script to _legacy, and add a new _flask version with modern Flask tooling. Decide which one to call via pvc-api-db-migrate using /etc/debian_version call. --- api-daemon/pvc-api-db-upgrade | 13 ++++++++- api-daemon/pvcapid-manage_flask.py | 29 +++++++++++++++++++ ...pid-manage.py => pvcapid-manage_legacy.py} | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 api-daemon/pvcapid-manage_flask.py rename api-daemon/{pvcapid-manage.py => pvcapid-manage_legacy.py} (94%) diff --git a/api-daemon/pvc-api-db-upgrade b/api-daemon/pvc-api-db-upgrade index 54a16bbe..2ea9bf28 100755 --- a/api-daemon/pvc-api-db-upgrade +++ b/api-daemon/pvc-api-db-upgrade @@ -11,5 +11,16 @@ if [[ ! -f ${PVC_CONFIG_FILE} ]]; then fi pushd /usr/share/pvc -./pvcapid-manage.py db upgrade + +case "$( cat /etc/debian_version )" in + 10.*|11.*) + # Debian 10 & 11 + ./pvcapid-manage_legacy.py db upgrade + ;; + *) + # Debian 12+ + flask --app ./pvcapid-manage_flask.py db upgrade + ;; +esac + popd diff --git a/api-daemon/pvcapid-manage_flask.py b/api-daemon/pvcapid-manage_flask.py new file mode 100755 index 00000000..37c7fc0c --- /dev/null +++ b/api-daemon/pvcapid-manage_flask.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +# pvcapid-manage_flask.py - PVC Database management tasks (via Flask CLI) +# Part of the Parallel Virtual Cluster (PVC) system +# +# Copyright (C) 2018-2022 Joshua M. Boniface +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################### + +from pvcapid.flaskapi import app, db +from pvcapid.models import * # noqa F401,F403 + +from flask_migrate import Migrate + +migrate = Migrate(app, db) + +# Call flask --app /usr/share/pvc/pvcapid-manage_flask.py db upgrade diff --git a/api-daemon/pvcapid-manage.py b/api-daemon/pvcapid-manage_legacy.py similarity index 94% rename from api-daemon/pvcapid-manage.py rename to api-daemon/pvcapid-manage_legacy.py index b63a8e1a..2988689a 100755 --- a/api-daemon/pvcapid-manage.py +++ b/api-daemon/pvcapid-manage_legacy.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# manage.py - PVC Database management tasks +# pvcapid-manage_legacy.py - PVC Database management tasks (Legacy) # Part of the Parallel Virtual Cluster (PVC) system # # Copyright (C) 2018-2022 Joshua M. Boniface