diff --git a/awx/main/migrations/0037_v320_release.py b/awx/main/migrations/0037_v320_release.py index 12408fda92..a9745354bd 100644 --- a/awx/main/migrations/0037_v320_release.py +++ b/awx/main/migrations/0037_v320_release.py @@ -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( diff --git a/awx/main/migrations/0038_v320_data_migrations.py b/awx/main/migrations/0038_v320_data_migrations.py new file mode 100644 index 0000000000..5b0f921cd6 --- /dev/null +++ b/awx/main/migrations/0038_v320_data_migrations.py @@ -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), + ] diff --git a/awx/main/migrations/_inventory_source.py b/awx/main/migrations/_inventory_source.py index af91d835cc..a157bb2eb6 100644 --- a/awx/main/migrations/_inventory_source.py +++ b/awx/main/migrations/_inventory_source.py @@ -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()