Skip to content

feat(db): promote CatalogueCategoryProperty.uid INDEX to CONSTRAINT #417

Description

@JanSmrcka

Context

PR #416 added a range INDEX on `CatalogueCategoryProperty.uid` (migration `20260511120000_add_catalogue_category_property_uid_index`) instead of a uniqueness CONSTRAINT, to avoid dirty-state risk if duplicate UIDs exist in prod data.

Every other identifier in the schema (`CatalogueItem.uid`, `Unit.uid`, `Manufacturer.name`, `User.uid`, `Role.uid`, `CatalogueCategoryPropertyType.uid`) uses a CONSTRAINT. CatalogueCategoryProperty is the inconsistent one.

Steps

  1. Audit prod for duplicates: `MATCH (p:CatalogueCategoryProperty) WITH p.uid AS u, count(*) AS c WHERE c > 1 RETURN u, c`.
  2. If clean → add migration `CREATE CONSTRAINT CatalogueCategoryProperty_uid_unique IF NOT EXISTS FOR (p:CatalogueCategoryProperty) REQUIRE p.uid IS UNIQUE` + drop the bare INDEX (constraint creates its own).
  3. If duplicates exist → data-cleanup migration first, then constraint.

Why

Closes the semantic gap, prevents accidental duplicate-UID creation in code paths that don't go through MERGE.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions