Skip to content

bug: safely enforce MacTrack site-name uniqueness #360

Description

@somethingwithproof

Problem

mac_track_sites has only a primary key on site_id, so duplicate site names—including duplicate Default rows—are structurally possible. The Default-site repair in #357 uses a database-scoped advisory lock and a conditional insert, which is safe on a single database server but is not a substitute for a unique constraint in proxied or multi-primary deployments.

Adding a unique index directly in the 1.2 release fix is unsafe because existing installations may already contain duplicate custom or Default names and their references must be reconciled deliberately.

Required validation

  • Reproduce upgrades containing duplicate Default and duplicate custom site names.
  • Define deterministic merge/rename behavior without losing device relationships or operator-authored metadata.
  • Add a guarded, restartable uniqueness migration for MariaDB and MySQL.
  • Verify new installs and upgrades end with an equivalent unique constraint.
  • Exercise concurrent creation without relying on connection-scoped advisory locks.
  • Treat duplicate-key outcomes as a satisfied postcondition when another writer wins.

Relationships

Found during review of #357. Coordinate with the broader schema work in #104 and the legacy migration defect in #359.

Activity

  1. somethingwithproof commented on Sep 6, 2026

    @somethingwithproof
    MemberAuthor

    Update from #357 review: the Default-site creation path now uses INSERT IGNORE with fixed site_id = 1, and its Docker race assigns distinct advisory-lock namespaces to all eight workers. That removes advisory-lock dependence for the Default-row invariant on both MariaDB and MySQL.

    This issue remains open for the broader migration problem: safely reconciling and preventing duplicate custom site names without losing device relationships or operator-authored metadata.

  2. somethingwithproof commented on Sep 6, 2026

    @somethingwithproof
    MemberAuthor

    Further #357 review found that fixing Default to site_id = 1 is unsafe: site deletion currently leaves mac_track_arp and mac_track_dot1x rows behind, so reusing ID 1 could misattribute orphaned history to the new Default site. That approach was reverted.

    #357 retains the single-primary advisory-lock improvement and now fails CLI installs non-zero plus retries from the poller. This issue remains the place to design topology-independent uniqueness together with legacy duplicate reconciliation and orphan cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

QABug found in QAbug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions