Skip to content

Automatically handle Custom Object Type schema upgrades created through changes to core mixins #391

@bctiemann

Description

@bctiemann

Plugin Version

v0.4.6

Proposed functionality

Important consideration: If changes are made to core mixins (the base classes that Custom Object models inherit from), there is currently no mechanism to generate migrations for the dynamically created Custom Object tables.

The Problem:

Custom Object models inherit from mixins like NetBoxModel, ChangeLoggingMixin, etc. When these core mixins are updated (e.g., new field added, field type changed), the changes need to propagate to:

  1. The dynamic Custom Object tables in the database
  2. Any related indexes, constraints, or triggers

Since Custom Objects don't have traditional migration files (they use runtime schema operations), there's no standard way to:

  • Detect that a mixin has changed
  • Generate the appropriate ALTER TABLE statements
  • Apply these changes across all existing Custom Object tables

Impact:

Scenario Current Behavior Desired Behavior
New field added to mixin Not applied to existing COT tables Auto-detect and apply
Field type changed in mixin Mismatch between model and table Migration generated and applied
Index added to mixin Missing on COT tables Created on all COT tables
NetBox upgrade with mixin changes Potential runtime errors Seamless upgrade

Possible Solutions:

  1. Mixin version tracking - Track which mixin version each COT was created with; compare on startup
  2. Schema introspection - Compare actual table schema to expected model schema; generate diffs
  3. Explicit upgrade command - manage.py upgrade_custom_objects that applies pending mixin changes
  4. Hook into NetBox migrations - Detect relevant core migrations and apply to COT tables

Use case

If changes are made to core mixins (the base classes that Custom Object models inherit from), there is currently no mechanism to generate migrations for the dynamically created Custom Object tables.

External dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions