Skip to content

Commit

Permalink
Fix deploy backward migrations (#2471)
Browse files Browse the repository at this point in the history
Fixed backward migrations for feature/deployment branch
  • Loading branch information
mkurek committed Jun 9, 2016
1 parent 7c50103 commit 9bd1797
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Expand Up @@ -27,13 +27,15 @@ def move_to_networks(apps, schema_editor):


def move_from_networks(apps, schema_editor):
DataCenterAsset = apps.get_model('data_center', 'DataCenterAsset')
IPAddress = apps.get_model('networks', 'IPAddress')
ips = IPAddress.objects.exclude(is_management=False, base_object=None)
ips = IPAddress.objects.filter(
is_management=True, base_object__asset__datacenterasset__isnull=False
)
for ip in ips:
ip.base_object.management_ip_old = ip.address
ip.base_object.management_hostname_old = ip.hostname
ip.base_object.save()
dca = ip.base_object.asset.datacenterasset
dca.management_ip_old = ip.address
dca.management_hostname_old = ip.hostname
dca.save()


class Migration(migrations.Migration):
Expand Down
7 changes: 6 additions & 1 deletion src/ralph/networks/migrations/0003_custom_link_ips_to_eth.py
Expand Up @@ -20,7 +20,12 @@ def move_from_base_object_to_ethernet(apps, schema_editor):


def move_from_ethernet_to_base_object(apps, schema_editor):
pass
Ethernet = apps.get_model('assets', 'Ethernet')
for eth in Ethernet.objects.filter(
ipaddress__isnull=False,
):
eth.ipaddress.base_object_id = eth.base_object_id
eth.ipaddress.save()


class Migration(migrations.Migration):
Expand Down
11 changes: 10 additions & 1 deletion src/ralph/networks/models/networks.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import ipaddress
import logging
import socket
import struct
from itertools import chain
Expand All @@ -9,6 +10,7 @@
from django.db import models, transaction
from django.db.models import Q
from django.db.models.signals import post_migrate
from django.db.utils import ProgrammingError
from django.dispatch import receiver
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
Expand All @@ -26,6 +28,8 @@
from ralph.networks.fields import IPNetwork
from ralph.networks.models.choices import IPAddressStatus

logger = logging.getLogger(__name__)


class NetworkKind(NamedMixin, models.Model):
class Meta:
Expand Down Expand Up @@ -585,4 +589,9 @@ def rebuild_handler(sender, **kwargs):
"""
# post_migrate is called after each app's migrations
if sender.name == 'ralph.' + Network._meta.app_label:
Network.objects.rebuild()
try:
Network.objects.rebuild()
except ProgrammingError:
# this may happen during unapplying initial migration for networks
# app
logger.warning('ProgrammingError during Network rebuilding')

0 comments on commit 9bd1797

Please sign in to comment.