mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Create a new 3.2 data migration file and adjust logging.
This commit is contained in:
@@ -10,8 +10,6 @@ from psycopg2.extensions import AsIs
|
|||||||
# AWX
|
# AWX
|
||||||
import awx.main.fields
|
import awx.main.fields
|
||||||
from awx.main.models import FactLatest
|
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):
|
class Migration(migrations.Migration):
|
||||||
@@ -37,9 +35,6 @@ class Migration(migrations.Migration):
|
|||||||
name='inventory',
|
name='inventory',
|
||||||
field=models.ForeignKey(related_name='inventory_sources', default=None, to='main.Inventory', null=True),
|
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
|
# Facts Latest
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
|||||||
25
awx/main/migrations/0038_v320_data_migrations.py
Normal file
25
awx/main/migrations/0038_v320_data_migrations.py
Normal 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),
|
||||||
|
]
|
||||||
@@ -2,7 +2,7 @@ import logging
|
|||||||
|
|
||||||
from django.db.models import Q
|
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):
|
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')
|
InventorySource = apps.get_model('main', 'InventorySource')
|
||||||
# see models/inventory.py SOURCE_CHOICES - ('', _('Manual'))
|
# see models/inventory.py SOURCE_CHOICES - ('', _('Manual'))
|
||||||
|
logger.debug("Removing all Manual InventorySource from database.")
|
||||||
InventorySource.objects.filter(source='').delete()
|
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
|
inventory = invsrc.deprecated_group.inventory if invsrc.deprecated_group else invsrc.inventory
|
||||||
name = '{0} - {1} - {2}'.format(invsrc.name, inventory.name, i)
|
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.name = name
|
||||||
invsrc.save()
|
invsrc.save()
|
||||||
|
|
||||||
@@ -38,4 +40,5 @@ def remove_inventory_source_with_no_inventory_link(apps, schema_editor):
|
|||||||
we can safely remove it.
|
we can safely remove it.
|
||||||
'''
|
'''
|
||||||
InventorySource = apps.get_model('main', 'InventorySource')
|
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()
|
InventorySource.objects.filter(Q(inventory__organization=None) & Q(deprecated_group__inventory=None)).delete()
|
||||||
|
|||||||
Reference in New Issue
Block a user