ArnesSI / netbox-inventory

Manage your hardware inventory in NetBox
MIT License
205 stars 21 forks source link

add unique constraint on asset_tag if asset has no owner #157

Closed matejv closed 4 months ago

matejv commented 5 months ago

and move all asset's unique_together to model contratints

see #149

matejv commented 5 months ago

If assets table contains assets with duplicate asset tags and not owner, DB migration will fail with:

Applying netbox_inventory.0007_alter_asset_unique_together_and_more...
...
django.db.utils.IntegrityError: could not create unique index "unique_asset_tag"
DETAIL:  Key (asset_tag)=(1110) is duplicated.

To hopefully prevent this from happening to users, I'll hold on merging this PR till the next major version. In the meantime I'll add a management script and a notification to the release notes to the preceding releases to allow people to check and fix their data beforehand.