Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike: Research Existing Models for Desirable FK, Related Names Changes #2960

Closed
Tracked by #2520
bryanculver opened this issue Dec 5, 2022 · 13 comments
Closed
Tracked by #2520
Assignees
Labels
type: spike Work neccessay to break out and plan epic/feature work.
Milestone

Comments

@bryanculver
Copy link
Member

bryanculver commented Dec 5, 2022

@bryanculver bryanculver added the type: spike Work neccessay to break out and plan epic/feature work. label Dec 5, 2022
@bryanculver bryanculver added this to the v2.0.0 milestone Dec 5, 2022
@bryanculver bryanculver changed the title Spike: Research Existing Models for Desirable FK, Related Names Changes - 2 Spike: Research Existing Models for Desirable FK, Related Names Changes Dec 8, 2022
@gsnider2195 gsnider2195 self-assigned this Dec 13, 2022
@gsnider2195
Copy link
Contributor

gsnider2195 commented Dec 13, 2022

circuits

  • rename Circuit.type to circuit_type
  • rename Circuit.termination_a to circuit_termination_a
  • rename Circuit.termination_z to circuit_termination_z
  • change CircuitTermination._path related_name from circuittermination to circuit_terminations
  • change CircuitTermination.circuit related_name from terminations to circuit_terminations

dcim

  • change ConsolePort.device related_name from consoleports to console_ports
  • change ConsolePort._path related_name from consoleport to console_ports
  • change ConsoleServerPort.device related_name from consoleserverports to console_server_ports
  • change ConsoleServerPort._path related_name from consoleserverport to console_server_ports
  • change PowerPort.device related_name from powerports to power_ports
  • change PowerPort._path related_name from powerport to power_ports
  • change PowerOutlet.device related_name from poweroutlets to power_outlets
  • change PowerOutlet._path related_name from poweroutlet to power_outlets
  • change PowerOutlet.power_port related_name from poweroutlets to power_outlets
  • change Interface._path related_name from interface to interfaces
  • rename Interface.parent_interface to parent
  • change Interface.parent_interface related_name from child_interfaces to children
  • change FrontPort.device related_name from frontports to front_ports
  • change FrontPort.rear_port related_name from frontports to front_ports
  • change RearPort.device related_name from rearports to rear_ports
  • change DeviceBay.device related_name from devicebays to device_bays
  • change InventoryItem.device related_name from inventoryitems to inventory_items
  • change InventoryItem.parent related_name from child_items to children
  • rename Device.local_context_schema to config_context_schema
  • change Device.local_context_schema related_name from device to devices
  • change Device.local_context_data_owner_content_type related_name from device to devices
  • change Device.device_type related_name from instances to devices
  • change Device.device_redundancy_group related_name from members to devices
  • change Device.secrets_group related_name from device to devices
  • change DeviceRedundancyGroup.secrets_group related_name from deviceredundancygroup to device_redundancy_groups
  • change ConsolePortTemplate.device_type related_name from consoleporttemplates to console_port_templates
  • change ConsoleServerPortTemplate.device_type related_name from consoleserverporttemplates to console_server_port_templates
  • change PowerPortTemplate.device_type related_name from powerporttemplates to power_port_templates
  • change PowerOutletTemplate.device_type related_name from poweroutlettemplates to power_outlet_templates
  • rename PowerOutletTemplate.power_port to power_port_template
  • change PowerOutletTemplate.power_port related_name from poweroutlet_templates to power_outlet_templates
  • change InterfaceTemplate.device_type related_name from interfacetemplates to interface_templates
  • change FrontPortTemplate.device_type related_name from frontporttemplates to front_port_templates
  • rename FrontPortTemplate.rear_port to rear_port_template
  • change FrontPortTemplate.rear_port related_name from frontport_templates to front_port_templates
  • change RearPortTemplate.device_type related_name from rearporttemplates to rear_port_templates
  • change DeviceBayTemplate.device_type related_name from devicebaytemplates to device_bay_templates
  • change PowerPanel.site related_name from powerpanel to power_panels
  • change PowerPanel.location related_name from powerpanels to power_panels
  • change PowerPanel.rack_group related_name from powerpanel to power_panels
  • change PowerFeed._path related_name from powerfeed to power_feeds
  • change PowerFeed.power_panel related_name from powerfeeds to power_feeds
  • change PowerFeed.rack related_name from powerfeed to power_feeds
  • rename Rack.group to rack_group
  • change RackReservation.rack related_name from reservations to rack_reservations
  • change RackReservation.tenant related_name from rackreservations to rack_reservations
  • change RackReservation.user related_name from rackreservation to rack_reservations

extras

  • change ObjectChange.user related_name from changes to object_changes
  • change ComputedField.content_type related_name from computedfield to computed_fields
  • rename CustomFieldChoice.field to custom_field
  • change CustomFieldChoice.field related_name from choices to custom_field_choices
  • change RelationshipAssociation.relationship related_name from associations to relationship_associations
  • change TaggedItem.tag related_name from extras_taggeditem_items to tagged_items
  • change GitRepository.secrets_group related_name from gitrepository to git_repositories
  • change DynamicGroup.content_type related_name from dynamicgroup to dynamic_groups
  • change JobHook.job related_name from job_hook to job_hooks
  • change JobLogEntry.job_result related_name from logs to job_log_entries
  • rename JobResult.job_model to job
  • change JobResult.job_model related_name from results to job_results
  • rename JobResult.schedule to scheduled_job
  • change JobResult.schedule related_name from jobresult to job_results
  • rename ScheduledJob.job_model to job
  • change ConfigContext.owner_content_type related_name from configcontext to config_contexts
  • rename ConfigContext.schema to config_context_schema
  • change ConfigContext.schema related_name from configcontext to config_contexts
  • change ConfigContextSchema.owner_content_type related_name from configcontextschema to config_context_schemas
  • change CustomLink.content_type related_name from customlink to custom_links
  • change ExportTemplate.owner_content_type related_name from export_template_owners to export_templates
  • change ExportTemplate.content_type related_name from exporttemplate to export_templates
  • change ImageAttachment.content_type related_name from imageattachment to image_attachments
  • change Note.assigned_object_type related_name from note to notes
  • change Note.user related_name from note to notes
  • change SecretsGroup.secrets related_name from groups to secrets_groups
  • rename SecretsGroupAssociation.group to secrets_group
  • change SecretsGroupAssociation.group related_name from secretsgroupassociation to secrets_group_associations
  • change SecretsGroupAssociation.secret related_name from secretsgroupassociation to secrets_group_associations

ipam

  • rename VLAN.group to vlan_group
  • rename Service.ipaddresses to ip_addresses

tenancy

  • rename Tenant.group to tenant_group

users

  • change User.groups related_name from user to users
  • rename User.user_permissions to permissions
  • change User.user_permissions related_name from user to users
  • change Group.permissions related_name from group to groups

virtualization

  • rename Cluster.type to cluster_type
  • rename Cluster.group to cluster_group
  • rename VirtualMachine.local_context_schema to config_context_schema
  • change VirtualMachine.local_context_schema related_name from virtualmachine to virtual_machines
  • change VirtualMachine.local_context_data_owner_content_type related_name from virtualmachine to virtual_machines
  • rename VMInterface.parent_interface to parent
  • change VMInterface.parent_interface related_name from child_interfaces to children

Abstract base class related names

These could potentially be changed by overloading the contribute_to_class method from django's RelatedField in StatusModel but I don't know if it's worth the effort.

Decided that this isn't worth the effort for now.

  • change Circuit.status related_name from circuits_circuit_related to circuits
  • change Interface.status related_name from dcim_interface_related to interfaces
  • change Device.status related_name from dcim_device_related to devices
  • change DeviceRedundancyGroup.status related_name from dcim_deviceredundancygroup_related to device_redundancy_groups
  • change Cable.status related_name from dcim_cable_related to cables
  • change Location.status related_name from dcim_location_related to locations
  • change PowerFeed.status related_name from dcim_powerfeed_related to power_feeds
  • change Rack.status related_name from dcim_rack_related to racks
  • change Site.status related_name from dcim_site_related to sites
  • change Prefix.status related_name from ipam_prefix_related to prefixes
  • change IPAddress.status related_name from ipam_ipaddress_related to ip_addresses
  • change VLAN.status related_name from ipam_vlan_related to vlans
  • change VirtualMachine.status related_name from virtualization_virtualmachine_related to virtual_machines

@gsnider2195
Copy link
Contributor

Drop the attached file in nautobot/core/management/commands/ and run nautobot-server fix_related_names to generate the above list. This could be useful for turning this into a lint check

fix_related_names.py.zip

@jathanism
Copy link
Contributor

The only concern I have are the recommendation for any status fields because those are automatically generated by way of including the StatusModel mixin:

https://github.com/nautobot/nautobot/blob/develop/nautobot/extras/models/statuses.py#L179

If there's a way we can introspect this easier and have the model's verbose_name_plural be used, I'd say change these related names, otherwise, exclude any status fields from this inventory.

@jathanism
Copy link
Contributor

Another one is if a related_name is set to + we might want to treat those separately, because there are some cases where we actually don’t want a reverse relationship due to complicated relationships like generic FK or m2m.

@glennmatthews
Copy link
Contributor

The status issue also applies to the upcoming role field/model... we should come up with a pattern here.

@glennmatthews
Copy link
Contributor

change Device.virtual_chassis related_name from members to devices
rename VirtualChassis.master to device

Having both VirtualChassis.device and VirtualChassis.devices would be confusing and I think it's a loss of clarity compared to master (is there a newer/better term we could use here?) and members

@glennmatthews
Copy link
Contributor

rename DeviceBay.installed_device to device
change DeviceBay.installed_device related_name from parent_bay to device_bays

Can't/shouldn't do these - a DeviceBay has both a device (the Device that contains this DeviceBay) and an installed_device (the Device that this DeviceBay contains). Similarly a Device has both a parent_bay (the DeviceBay that contains this Device) and device_bays (the DeviceBays that this Device contains).

@glennmatthews
Copy link
Contributor

glennmatthews commented Dec 15, 2022

rename Rack.role to rack_role
rename ConfigContext.roles to device_roles
rename VirtualMachine.role to device_role

Shouldn't do these since we're collapsing the Role models.

@glennmatthews
Copy link
Contributor

change VMInterface.virtual_machine related_name from interfaces to vm_interfaces

IMO we shouldn't do this since it'll be one more breaking change we'll have to do/revert as a part of #1178.

@gsnider2195
Copy link
Contributor

change Device.virtual_chassis related_name from members to devices
rename VirtualChassis.master to device

Having both VirtualChassis.device and VirtualChassis.devices would be confusing and I think it's a loss of clarity compared to master (is there a newer/better term we could use here?) and members

I'd rather leave as-is than try to fix the confusing terminology as part of this spike. There's plenty of work to be done here fixing consistency in field and related names (powerports to power_ports).

@gsnider2195
Copy link
Contributor

The only concern I have are the recommendation for any status fields because those are automatically generated by way of including the StatusModel mixin:

https://github.com/nautobot/nautobot/blob/develop/nautobot/extras/models/statuses.py#L179

If there's a way we can introspect this easier and have the model's verbose_name_plural be used, I'd say change these related names, otherwise, exclude any status fields from this inventory.

Looks like this won't be easy. We'd have to overload the contribute_to_class method from django's RelatedField. I'd lean toward leaving it as-is.

@jathanism
Copy link
Contributor

The status issue also applies to the upcoming role field/model... we should come up with a pattern here.

Let's just align on whatever that should be the interpolated related_name that I providdd for Status, or something like it.

@gsnider2195
Copy link
Contributor

  • change VirtualMachine.local_context_data_owner_content_type related_name from virtualmachine to virtual_machines

We could standardize ForeignKey.related_name on abstract base classes to %(app_label)s_%(class)s_related to match StatusModel.status. Self-referencing foreign keys would be an exception and typically the related name would be children.

This would mean we would need to change the follow abstract base classes and keys:

dcim.ComponentTemplateModel

  • change device_type.related_name from %(class)ss to %(app_label)s_%(class)s_related

dcim.ComponentModel

  • change device.related_name from %(class)ss to %(app_label)s_%(class)s_related

dcim.PathEndpoint

  • change _path.related_name from the default to %(app_label)s_%(class)s_related

extras.ConfigContextModel

  • change local_context_schema.related_name from the default to %(app_label)s_%(class)s_related
  • change local_context_data_owner_content_type.related_name from the default to %(app_label)s_%(class)s_related

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: spike Work neccessay to break out and plan epic/feature work.
Projects
No open projects
Archived in project
Development

No branches or pull requests

4 participants