mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* Add migration for service level and terms * Add service level and terms to UI and serializer, as well as data/enum * Wire up data/enum endpoint and loader * remove proto_ from ix UI * derive fields for proto_unicast and proto_ipv6 * update tests for readonly fields * Fix query for protocols * Fix api bug with protocol * add readonly fields to django admin * rename readonly fields * Add translation to names * Add pdb api test for suggested facility re-add * Add printing debuggin test * add printing debugging serializer * Update _undelete with _reapprove to handle pending cases * Update tests (one is still failing) * adjust suggest test * Add ix_count to fac (834) * Add test for ix_count on fac (834) * Add fac_count to IX (836) * add ix_count and fac_count to Network * Refactor ix net_count filtering * Add filtering for 834, 835, 836 * Remove duplicates from the Network's ix_count * Setup Network for ix_count and fac_count (835) * initial obj_counts for Facilities and Exchanges * Add signals for updates to all counts * add migration * Add print statements to test * introduce reversion to tests * rename network count to net count across codebase * fix network_count typo * add migration to set default vals * fix filter tests for obj_counts * speed up migration * fix failing tests * fix final test * sort out migration tree and add fac offered fields * update frontend for facility dropdown offered_resilience * First pass at advanced api search for user story 1 * melissa geo lookup first steps * fix migration hierarchy * working melissa integration * begin ending filters for api endpoints * add more org_present endpoints * add search for IXs that match multiple networks * extend logic to facility * Add service level and terms to advanced search * use address2 field for lookup * melissa tests * cleanup and docs * uncomment offered_power * developed offered_power component * fix geo normalize existing cmd normalize state * change migration to match django-peeringdb * add offered_space field * Fill out remaining api filter fields * Add org_not_present endpoint filter * fix unit input ux * more ux fixes * remove merge cruft * google for geocoding various melissa improvements (consider result quality) * fix tests * refactor org_preset and org_not_present queries * ix capacity api filters * ix capacity filters for #802 advanced search ux for #802 * finalize advanced search UX for #802 * css fixes * remove cruft * fix net_count fac_count queries * add new fields to create facility (#800) tests for #802 and #800 * fix tests * remove #800 changes * fix capacity search * more #800 changes to remove * django-peeringdb 2.7.0 and pipenv relock * black format * pin black version Co-authored-by: Elliot Frank <elliot@20c.com> Co-authored-by: Stefan Pratter <stefan@20c.com>
119 lines
4.0 KiB
Python
119 lines
4.0 KiB
Python
# Generated by Django 2.2.17 on 2021-01-05 21:39
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
from django.db import migrations
|
|
from django.db.models import Count
|
|
|
|
from peeringdb_server.signals import disable_auto_now_and_save
|
|
|
|
|
|
def populate_network_counts(apps, schema_editor):
|
|
Network = apps.get_model("peeringdb_server", "Network")
|
|
NetworkIXLan = apps.get_model("peeringdb_server", "NetworkIXLan")
|
|
NetworkFacility = apps.get_model("peeringdb_server", "NetworkFacility")
|
|
|
|
print("This migration may take several minutes ...")
|
|
print("Populating network ix_count and fac_count values")
|
|
|
|
for network in Network.handleref.all():
|
|
if network.id % 10 == 0:
|
|
print(network)
|
|
try:
|
|
network.ix_count = (
|
|
NetworkIXLan.handleref.select_related("ixlan__ix")
|
|
.filter(network_id=network.id, status="ok")
|
|
.aggregate(ix_count=Count("ixlan__ix_id", distinct=True))
|
|
)["ix_count"]
|
|
|
|
except ObjectDoesNotExist:
|
|
pass
|
|
try:
|
|
network.fac_count = (
|
|
NetworkFacility.handleref.select_related("facility")
|
|
.filter(network_id=network.id, status="ok")
|
|
.aggregate(fac_count=Count("facility_id", distinct=True))
|
|
)["fac_count"]
|
|
except ObjectDoesNotExist:
|
|
pass
|
|
|
|
disable_auto_now_and_save(network)
|
|
|
|
|
|
def populate_ix_counts(apps, schema_editor):
|
|
InternetExchange = apps.get_model("peeringdb_server", "InternetExchange")
|
|
NetworkIXLan = apps.get_model("peeringdb_server", "NetworkIXLan")
|
|
InternetExchangeFacility = apps.get_model(
|
|
"peeringdb_server", "InternetExchangeFacility"
|
|
)
|
|
|
|
print("Populating Exchange net_count and fac_count values")
|
|
|
|
for ix in InternetExchange.handleref.all():
|
|
if ix.id % 10 == 0:
|
|
print(ix)
|
|
|
|
try:
|
|
ix.net_count = (
|
|
NetworkIXLan.handleref.select_related("network")
|
|
.filter(ixlan__ix_id=ix.id, status="ok")
|
|
.aggregate(net_count=Count("network_id", distinct=True))
|
|
)["net_count"]
|
|
except ObjectDoesNotExist:
|
|
pass
|
|
try:
|
|
ix.fac_count = (
|
|
InternetExchangeFacility.handleref.select_related("facility")
|
|
.filter(ix_id=ix.id, status="ok")
|
|
.aggregate(fac_count=Count("facility_id", distinct=True))
|
|
)["fac_count"]
|
|
|
|
except ObjectDoesNotExist:
|
|
pass
|
|
|
|
disable_auto_now_and_save(ix)
|
|
|
|
|
|
def populate_facility_counts(apps, schema_editor):
|
|
Facility = apps.get_model("peeringdb_server", "Facility")
|
|
print("Populating Facility net_count and ix_count values")
|
|
NetworkFacility = apps.get_model("peeringdb_server", "NetworkFacility")
|
|
InternetExchangeFacility = apps.get_model(
|
|
"peeringdb_server", "InternetExchangeFacility"
|
|
)
|
|
for facility in Facility.handleref.all():
|
|
if facility.id % 10 == 0:
|
|
print(facility)
|
|
try:
|
|
facility.ix_count = (
|
|
InternetExchangeFacility.handleref.select_related("ix")
|
|
.filter(facility_id=facility.id, status="ok")
|
|
.aggregate(ix_count=Count("ix_id", distinct=True))
|
|
)["ix_count"]
|
|
|
|
except ObjectDoesNotExist:
|
|
pass
|
|
try:
|
|
facility.net_count = (
|
|
NetworkFacility.handleref.select_related("network")
|
|
.filter(facility_id=facility.id, status="ok")
|
|
.aggregate(net_count=Count("network_id", distinct=True))
|
|
)["net_count"]
|
|
|
|
except ObjectDoesNotExist:
|
|
pass
|
|
|
|
disable_auto_now_and_save(facility)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("peeringdb_server", "0070_add_obj_counts"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(populate_network_counts, migrations.RunPython.noop),
|
|
migrations.RunPython(populate_ix_counts, migrations.RunPython.noop),
|
|
migrations.RunPython(populate_facility_counts, migrations.RunPython.noop),
|
|
]
|