
from django.db import migrations
from django.db.migrations import RunPython


def forward(apps, schema):
    Node = apps.get_model("thefederation", "Node")
    for node in Node.objects.filter(host__contains=":"):
        node.host = node.host.split(":")[0]
        if node.name.split(':')[0] == node.host:
            node.name = node.host
        Node.objects.filter(id=node.id).update(host=node.host, name=node.name)


class Migration(migrations.Migration):

    dependencies = [
        ('thefederation', '0019_add_some_defaults_for_node_organization_fields'),
    ]

    operations = [
        RunPython(forward, RunPython.noop)
    ]


from django.db import migrations, IntegrityError
from django.db.migrations import RunPython


def forward(apps, schema):
    Node = apps.get_model("thefederation", "Node")
    for node in Node.objects.filter(host__contains=":"):
        node.host = node.host.split(":")[0]
        if node.name.split(':')[0] == node.host:
            node.name = node.host
        try:
            Node.objects.filter(id=node.id).update(host=node.host, name=node.name)
        except IntegrityError:
            pass


class Migration(migrations.Migration):

    dependencies = [
        ('thefederation', '0019_add_some_defaults_for_node_organization_fields'),
    ]

    operations = [
        RunPython(forward, RunPython.noop)
    ]

Make port removing migrating a bit less flaky
Make port removing migrating a bit less flaky

  
- from django.db import migrations
+ from django.db import migrations, IntegrityError
  from django.db.migrations import RunPython
  
  
  def forward(apps, schema):
      Node = apps.get_model("thefederation", "Node")
      for node in Node.objects.filter(host__contains=":"):
          node.host = node.host.split(":")[0]
          if node.name.split(':')[0] == node.host:
              node.name = node.host
+         try:
-         Node.objects.filter(id=node.id).update(host=node.host, name=node.name)
+             Node.objects.filter(id=node.id).update(host=node.host, name=node.name)
+         except IntegrityError:
+             pass
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('thefederation', '0019_add_some_defaults_for_node_organization_fields'),
      ]
  
      operations = [
          RunPython(forward, RunPython.noop)
      ]
  
Make port removing migrating a bit less flaky
## Code Before:

from django.db import migrations
from django.db.migrations import RunPython


def forward(apps, schema):
    Node = apps.get_model("thefederation", "Node")
    for node in Node.objects.filter(host__contains=":"):
        node.host = node.host.split(":")[0]
        if node.name.split(':')[0] == node.host:
            node.name = node.host
        Node.objects.filter(id=node.id).update(host=node.host, name=node.name)


class Migration(migrations.Migration):

    dependencies = [
        ('thefederation', '0019_add_some_defaults_for_node_organization_fields'),
    ]

    operations = [
        RunPython(forward, RunPython.noop)
    ]

## Instruction:
Make port removing migrating a bit less flaky
## Code After:

from django.db import migrations, IntegrityError
from django.db.migrations import RunPython


def forward(apps, schema):
    Node = apps.get_model("thefederation", "Node")
    for node in Node.objects.filter(host__contains=":"):
        node.host = node.host.split(":")[0]
        if node.name.split(':')[0] == node.host:
            node.name = node.host
        try:
            Node.objects.filter(id=node.id).update(host=node.host, name=node.name)
        except IntegrityError:
            pass


class Migration(migrations.Migration):

    dependencies = [
        ('thefederation', '0019_add_some_defaults_for_node_organization_fields'),
    ]

    operations = [
        RunPython(forward, RunPython.noop)
    ]
