From e2870f2b3ed640a629fc51017c6cde80039d52a6 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 19 Jul 2022 19:02:21 +0200 Subject: [PATCH] fix 2b90b41a556a_create_placeholders by null enviroment --- .../2b90b41a556a_create_placeholders.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ereuse_devicehub/migrations/versions/2b90b41a556a_create_placeholders.py b/ereuse_devicehub/migrations/versions/2b90b41a556a_create_placeholders.py index 8aa2b651..90180c20 100644 --- a/ereuse_devicehub/migrations/versions/2b90b41a556a_create_placeholders.py +++ b/ereuse_devicehub/migrations/versions/2b90b41a556a_create_placeholders.py @@ -7,6 +7,8 @@ Create Date: 2022-07-19 12:17:16.690865 """ import copy +from alembic import context, op + from ereuse_devicehub.config import DevicehubConfig from ereuse_devicehub.db import db from ereuse_devicehub.devicehub import Devicehub @@ -36,6 +38,13 @@ branch_labels = None depends_on = None +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + + def init_app(): app = Devicehub(inventory=DevicehubConfig.DB_SCHEMA) app.app_context().push() @@ -207,6 +216,11 @@ def remove_placeholders(): def upgrade(): + con = op.get_bind() + devices = con.execute(f'select * from {get_inv()}.device') + if not list(devices): + return + init_app() clone_computers() manual_actions() @@ -214,6 +228,11 @@ def upgrade(): def downgrade(): + con = op.get_bind() + devices = con.execute(f'select * from {get_inv()}.device') + if not list(devices): + return + init_app() remove_manual_actions() change_lot()