def close_previously_fixed_incidents_forward(apps, schema_editor):
    """Close incidents that were fixed before introducing the "closed"
    attribute."""
    Incident = apps.get_model('statusboard', 'incident')
    db_alias = schema_editor.connection.alias
    for i in Incident.objects.using(db_alias).order_by('-created').all():
        if i.updates.exists():
            i.closed = i.updates.latest('created').status == 3
            i.save()
