From 29533a0f52eac4f99e8e06a5ed49043eedd99e52 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 23 Sep 2015 18:29:04 +0200 Subject: tools/upgrade: Support multiple databases Do not use the global django connection object but the matching instance from the django connections list. --- tools/upgrade/1.3/migrate_dbstats.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/upgrade/1.3/migrate_dbstats.py b/tools/upgrade/1.3/migrate_dbstats.py index 2a2a112e9..c788aae37 100755 --- a/tools/upgrade/1.3/migrate_dbstats.py +++ b/tools/upgrade/1.3/migrate_dbstats.py @@ -8,7 +8,8 @@ import logging import time import Bcfg2.Logger import Bcfg2.Options -from django.db import connection, transaction, backend +from Bcfg2.DBSettings import get_db_label +from django.db import transaction, backend, connections from Bcfg2.Server.Admin import UpdateReports from Bcfg2.Reporting.utils import BatchFetch from Bcfg2.Reporting.Compat import transaction @@ -28,7 +29,8 @@ def _quote(value): global _our_backend if not _our_backend: try: - _our_backend = backend.DatabaseOperations(connection) + _our_backend = backend.DatabaseOperations( + connections[get_db_label('Reporting')]) except TypeError: _our_backend = backend.DatabaseOperations() return _our_backend.quote_name(value) @@ -178,7 +180,7 @@ def _shove(old_table, new_table, columns): cols, _quote(old_table)) - cursor = connection.cursor() + cursor = connections[get_db_label('Reporting')].cursor() cursor.execute(sql) cursor.close() -- cgit v1.2.3-1-g7c22