mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Closes #14436: Add PostgreSQL indexes for all GenericForeignKeys
This commit is contained in:
parent
5d2f499ffb
commit
20f0858c2e
17
netbox/core/migrations/0010_gfk_indexes.py
Normal file
17
netbox/core/migrations/0010_gfk_indexes.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.2.7 on 2023-12-07 16:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0009_configrevision'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name='job',
|
||||
index=models.Index(fields=['object_type', 'object_id'], name='core_job_object__c664ac_idx'),
|
||||
),
|
||||
]
|
@ -106,6 +106,9 @@ class Job(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created']
|
||||
indexes = (
|
||||
models.Index(fields=('object_type', 'object_id')),
|
||||
)
|
||||
verbose_name = _('job')
|
||||
verbose_name_plural = _('jobs')
|
||||
|
||||
|
25
netbox/dcim/migrations/0184_gfk_indexes.py
Normal file
25
netbox/dcim/migrations/0184_gfk_indexes.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Generated by Django 4.2.7 on 2023-12-07 16:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dcim', '0183_protect_child_interfaces'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name='cabletermination',
|
||||
index=models.Index(fields=['termination_type', 'termination_id'], name='dcim_cablet_termina_884752_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='inventoryitem',
|
||||
index=models.Index(fields=['component_type', 'component_id'], name='dcim_invent_compone_0560bb_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='inventoryitemtemplate',
|
||||
index=models.Index(fields=['component_type', 'component_id'], name='dcim_invent_compone_77b5f8_idx'),
|
||||
),
|
||||
]
|
@ -298,6 +298,9 @@ class CableTermination(ChangeLoggedModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('cable', 'cable_end', 'pk')
|
||||
indexes = (
|
||||
models.Index(fields=('termination_type', 'termination_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('termination_type', 'termination_id'),
|
||||
|
@ -749,6 +749,9 @@ class InventoryItemTemplate(MPTTModel, ComponentTemplateModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('device_type__id', 'parent__id', '_name')
|
||||
indexes = (
|
||||
models.Index(fields=('component_type', 'component_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('device_type', 'parent', 'name'),
|
||||
|
@ -1250,6 +1250,9 @@ class InventoryItem(MPTTModel, ComponentModel, TrackingModelMixin):
|
||||
|
||||
class Meta:
|
||||
ordering = ('device__id', 'parent__id', '_name')
|
||||
indexes = (
|
||||
models.Index(fields=('component_type', 'component_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('device', 'parent', 'name'),
|
||||
|
@ -91,6 +91,10 @@ class Migration(migrations.Migration):
|
||||
name='tags',
|
||||
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='eventrule',
|
||||
index=models.Index(fields=['action_object_type', 'action_object_id'], name='extras_even_action__d9e2af_idx'),
|
||||
),
|
||||
|
||||
# Replicate Webhook data
|
||||
migrations.RunPython(move_webhooks),
|
||||
|
37
netbox/extras/migrations/0103_gfk_indexes.py
Normal file
37
netbox/extras/migrations/0103_gfk_indexes.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Generated by Django 4.2.7 on 2023-12-07 16:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0102_move_configrevision'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name='bookmark',
|
||||
index=models.Index(fields=['object_type', 'object_id'], name='extras_book_object__2df6b4_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='imageattachment',
|
||||
index=models.Index(fields=['content_type', 'object_id'], name='extras_imag_content_94728e_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='journalentry',
|
||||
index=models.Index(fields=['assigned_object_type', 'assigned_object_id'], name='extras_jour_assigne_76510f_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='objectchange',
|
||||
index=models.Index(fields=['changed_object_type', 'changed_object_id'], name='extras_obje_changed_927fe5_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='objectchange',
|
||||
index=models.Index(fields=['related_object_type', 'related_object_id'], name='extras_obje_related_bfcdef_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='stagedchange',
|
||||
index=models.Index(fields=['object_type', 'object_id'], name='extras_stag_object__4734d5_idx'),
|
||||
),
|
||||
]
|
@ -94,6 +94,10 @@ class ObjectChange(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ['-time']
|
||||
indexes = (
|
||||
models.Index(fields=('changed_object_type', 'changed_object_id')),
|
||||
models.Index(fields=('related_object_type', 'related_object_id')),
|
||||
)
|
||||
verbose_name = _('object change')
|
||||
verbose_name_plural = _('object changes')
|
||||
|
||||
|
@ -132,6 +132,9 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
indexes = (
|
||||
models.Index(fields=('action_object_type', 'action_object_id')),
|
||||
)
|
||||
verbose_name = _('event rule')
|
||||
verbose_name_plural = _('event rules')
|
||||
|
||||
@ -631,6 +634,9 @@ class ImageAttachment(ChangeLoggedModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('name', 'pk') # name may be non-unique
|
||||
indexes = (
|
||||
models.Index(fields=('content_type', 'object_id')),
|
||||
)
|
||||
verbose_name = _('image attachment')
|
||||
verbose_name_plural = _('image attachments')
|
||||
|
||||
@ -720,6 +726,9 @@ class JournalEntry(CustomFieldsMixin, CustomLinksMixin, TagsMixin, ExportTemplat
|
||||
|
||||
class Meta:
|
||||
ordering = ('-created',)
|
||||
indexes = (
|
||||
models.Index(fields=('assigned_object_type', 'assigned_object_id')),
|
||||
)
|
||||
verbose_name = _('journal entry')
|
||||
verbose_name_plural = _('journal entries')
|
||||
|
||||
@ -769,6 +778,9 @@ class Bookmark(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ('created', 'pk')
|
||||
indexes = (
|
||||
models.Index(fields=('object_type', 'object_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('object_type', 'object_id', 'user'),
|
||||
|
@ -90,6 +90,9 @@ class StagedChange(ChangeLoggedModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('pk',)
|
||||
indexes = (
|
||||
models.Index(fields=('object_type', 'object_id')),
|
||||
)
|
||||
verbose_name = _('staged change')
|
||||
verbose_name_plural = _('staged changes')
|
||||
|
||||
|
25
netbox/ipam/migrations/0069_gfk_indexes.py
Normal file
25
netbox/ipam/migrations/0069_gfk_indexes.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Generated by Django 4.2.7 on 2023-12-07 16:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ipam', '0068_move_l2vpn'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name='fhrpgroupassignment',
|
||||
index=models.Index(fields=['interface_type', 'interface_id'], name='ipam_fhrpgr_interfa_2acc3f_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='ipaddress',
|
||||
index=models.Index(fields=['assigned_object_type', 'assigned_object_id'], name='ipam_ipaddr_assigne_890ab8_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='vlangroup',
|
||||
index=models.Index(fields=['scope_type', 'scope_id'], name='ipam_vlangr_scope_t_9da557_idx'),
|
||||
),
|
||||
]
|
@ -101,6 +101,9 @@ class FHRPGroupAssignment(ChangeLoggedModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('-priority', 'pk')
|
||||
indexes = (
|
||||
models.Index(fields=('interface_type', 'interface_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('interface_type', 'interface_id', 'group'),
|
||||
|
@ -780,9 +780,10 @@ class IPAddress(PrimaryModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('address', 'pk') # address may be non-unique
|
||||
indexes = [
|
||||
indexes = (
|
||||
models.Index(Cast(Host('address'), output_field=IPAddressField()), name='ipam_ipaddress_host'),
|
||||
]
|
||||
models.Index(fields=('assigned_object_type', 'assigned_object_id')),
|
||||
)
|
||||
verbose_name = _('IP address')
|
||||
verbose_name_plural = _('IP addresses')
|
||||
|
||||
|
@ -68,6 +68,9 @@ class VLANGroup(OrganizationalModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('name', 'pk') # Name may be non-unique
|
||||
indexes = (
|
||||
models.Index(fields=('scope_type', 'scope_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('scope_type', 'scope_id', 'name'),
|
||||
|
17
netbox/tenancy/migrations/0013_gfk_indexes.py
Normal file
17
netbox/tenancy/migrations/0013_gfk_indexes.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.2.7 on 2023-12-07 16:09
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tenancy', '0012_contactassignment_custom_fields'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name='contactassignment',
|
||||
index=models.Index(fields=['content_type', 'object_id'], name='tenancy_con_content_693ff4_idx'),
|
||||
),
|
||||
]
|
@ -141,6 +141,9 @@ class ContactAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, Chan
|
||||
|
||||
class Meta:
|
||||
ordering = ('priority', 'contact')
|
||||
indexes = (
|
||||
models.Index(fields=('content_type', 'object_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('content_type', 'object_id', 'contact', 'role'),
|
||||
|
@ -219,6 +219,10 @@ class Migration(migrations.Migration):
|
||||
'ordering': ('tunnel', 'role', 'pk'),
|
||||
},
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='tunneltermination',
|
||||
index=models.Index(fields=['termination_type', 'termination_id'], name='vpn_tunnelt_termina_c1f04b_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='tunneltermination',
|
||||
constraint=models.UniqueConstraint(fields=('termination_type', 'termination_id'), name='vpn_tunneltermination_termination', violation_error_message='An object may be terminated to only one tunnel at a time.'),
|
||||
|
@ -70,4 +70,8 @@ class Migration(migrations.Migration):
|
||||
name='vpn_l2vpntermination_assigned_object'
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='l2vpntermination',
|
||||
index=models.Index(fields=['assigned_object_type', 'assigned_object_id'], name='vpn_l2vpnte_assigne_9c55f8_idx'),
|
||||
),
|
||||
]
|
||||
|
@ -104,6 +104,9 @@ class L2VPNTermination(NetBoxModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ('l2vpn',)
|
||||
indexes = (
|
||||
models.Index(fields=('assigned_object_type', 'assigned_object_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('assigned_object_type', 'assigned_object_id'),
|
||||
|
@ -143,6 +143,9 @@ class TunnelTermination(CustomFieldsMixin, CustomLinksMixin, TagsMixin, ChangeLo
|
||||
|
||||
class Meta:
|
||||
ordering = ('tunnel', 'role', 'pk')
|
||||
indexes = (
|
||||
models.Index(fields=('termination_type', 'termination_id')),
|
||||
)
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('termination_type', 'termination_id'),
|
||||
|
Loading…
Reference in New Issue
Block a user