netboxlabs / netbox-branching

Official NetBox Labs plugin that implements git-like branching functionality for NetBox
http://netboxlabs.com
Other
49 stars 0 forks source link

Under the branch views, group change records by request #6

Open jeremystretch opened 2 months ago

jeremystretch commented 2 months ago

Plugin Version

v0.2.0

Proposed functionality

When displaying a list of change records, group each tranche of records by request ID. The list entry should convey a summary of the changes therein (e.g. "created 48 interfaces") and retain some mechanism for viewing the individual records.

Use case

This will make the change log easier to interpret and simplify the review process.

External dependencies

No response

jeremystretch commented 2 months ago

An example SQL query that may help here:

SELECT * FROM (
    SELECT
        DISTINCT ON (request_id, changed_object_type_id)
        time,
        request_id,
        changed_object_type_id,
        (
            SELECT COUNT(*) FROM branch_ohhzxzdu.core_objectchange
            WHERE request_id=T1.request_id AND changed_object_type_id=T1.changed_object_type_id AND action='create'
        ) AS created,
        (
            SELECT COUNT(*) FROM branch_ohhzxzdu.core_objectchange
            WHERE request_id=T1.request_id AND changed_object_type_id=T1.changed_object_type_id AND action='update'
        ) AS updated,
        (
            SELECT COUNT(*) FROM branch_ohhzxzdu.core_objectchange
            WHERE request_id=T1.request_id AND changed_object_type_id=T1.changed_object_type_id AND action='delete'
        ) AS deleted
        FROM branch_ohhzxzdu.core_objectchange T1
        ORDER BY request_id, changed_object_type_id, time
    ) changes
    ORDER BY time
;