mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 04:31:21 -03:30
add method to obtain the migration state of Tower
This commit is contained in:
parent
ce0096f308
commit
87af8f7a38
@ -19,6 +19,7 @@ from rest_framework.fields import empty, SkipField
|
||||
|
||||
# Tower
|
||||
from awx.main.utils import encrypt_field, decrypt_field
|
||||
from awx.main.utils.db import get_tower_migration_version
|
||||
from awx.conf import settings_registry
|
||||
from awx.conf.models import Setting
|
||||
|
||||
@ -59,7 +60,10 @@ def _log_database_error():
|
||||
try:
|
||||
yield
|
||||
except (ProgrammingError, OperationalError) as e:
|
||||
logger.warning('Database settings are not available, using defaults (%s)', e, exc_info=True)
|
||||
if get_tower_migration_version() < '310':
|
||||
logger.info('Using default settings until version 3.1 migration.')
|
||||
else:
|
||||
logger.warning('Database settings are not available, using defaults (%s)', e, exc_info=True)
|
||||
finally:
|
||||
pass
|
||||
|
||||
|
||||
22
awx/main/utils/db.py
Normal file
22
awx/main/utils/db.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright (c) 2017 Ansible by Red Hat
|
||||
# All Rights Reserved.
|
||||
|
||||
# Django database
|
||||
from django.db.migrations.loader import MigrationLoader
|
||||
from django.db import connection
|
||||
|
||||
# Python
|
||||
import re
|
||||
|
||||
|
||||
def get_tower_migration_version():
|
||||
loader = MigrationLoader(connection, ignore_no_migrations=True)
|
||||
v = '000'
|
||||
for app_name, migration_name in loader.applied_migrations:
|
||||
if app_name == 'main':
|
||||
version_captures = re.findall('^[0-9]{4}_v([0-9]{3})_', migration_name)
|
||||
if len(version_captures) == 1:
|
||||
migration_version = version_captures[0]
|
||||
if migration_version > v:
|
||||
v = migration_version
|
||||
return v
|
||||
Loading…
x
Reference in New Issue
Block a user