Create a new 3.2 data migration file and adjust logging.

This commit is contained in:
Wayne Witzel III
2017-04-11 14:55:14 -04:00
parent 91f3e665cb
commit 7cabe45e63
3 changed files with 29 additions and 6 deletions

View File

@@ -10,8 +10,6 @@ from psycopg2.extensions import AsIs
# AWX
import awx.main.fields
from awx.main.models import FactLatest
from awx.main.migrations import _inventory_source as invsrc
from awx.main.migrations import _migration_utils as migration_utils
class Migration(migrations.Migration):
@@ -37,9 +35,6 @@ class Migration(migrations.Migration):
name='inventory',
field=models.ForeignKey(related_name='inventory_sources', default=None, to='main.Inventory', null=True),
),
migrations.RunPython(migration_utils.set_current_apps_for_migrations),
migrations.RunPython(invsrc.remove_manual_inventory_sources),
migrations.RunPython(invsrc.rename_inventory_sources),
# Facts Latest
migrations.CreateModel(

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Python
from __future__ import unicode_literals
# Django
from django.db import migrations
# AWX
from awx.main.migrations import _inventory_source as invsrc
from awx.main.migrations import _migration_utils as migration_utils
class Migration(migrations.Migration):
dependencies = [
('main', '0037_v320_release'),
]
operations = [
# Inventory Refresh
migrations.RunPython(migration_utils.set_current_apps_for_migrations),
migrations.RunPython(invsrc.remove_manual_inventory_sources),
migrations.RunPython(invsrc.remove_inventory_source_with_no_inventory_link),
migrations.RunPython(invsrc.rename_inventory_sources),
]

View File

@@ -2,7 +2,7 @@ import logging
from django.db.models import Q
logger = logging.getLogger('invsrc_migrations')
logger = logging.getLogger('awx.main.migrations')
def remove_manual_inventory_sources(apps, schema_editor):
@@ -12,6 +12,7 @@ def remove_manual_inventory_sources(apps, schema_editor):
'''
InventorySource = apps.get_model('main', 'InventorySource')
# see models/inventory.py SOURCE_CHOICES - ('', _('Manual'))
logger.debug("Removing all Manual InventorySource from database.")
InventorySource.objects.filter(source='').delete()
@@ -29,6 +30,7 @@ def rename_inventory_sources(apps, schema_editor):
inventory = invsrc.deprecated_group.inventory if invsrc.deprecated_group else invsrc.inventory
name = '{0} - {1} - {2}'.format(invsrc.name, inventory.name, i)
logger.debug("Renaming InventorySource({0}) {1} -> {2}".format(invsrc.pk, invsrc.name, name))
invsrc.name = name
invsrc.save()
@@ -38,4 +40,5 @@ def remove_inventory_source_with_no_inventory_link(apps, schema_editor):
we can safely remove it.
'''
InventorySource = apps.get_model('main', 'InventorySource')
logger.debug("Removing all InventorySource that have no link to an Inventory from database.")
InventorySource.objects.filter(Q(inventory__organization=None) & Q(deprecated_group__inventory=None)).delete()