Skip to content

Normalize prefixes from mod-rs with hyphens, make sure hrid count sta… - #866

Open
kurtnordstrom wants to merge 4 commits into
mainfrom
prefix-export-fix
Open

kurtnordstrom wants to merge 4 commits into
mainfrom
prefix-export-fix

Conversation

@kurtnordstrom

Copy link
Copy Markdown
Contributor

…ys above highest imported value

@kurtnordstrom
kurtnordstrom marked this pull request as ready for review November 13, 2026 22:04
Copilot AI balanced review requested due to automatic review settings November 13, 2026 22:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical ID-collision risks remain because concurrent imports can regress the sequence and hyphenated prefixes silently bypass sequence advancement.

2 open issues
What changed in this PR

This PR updates mod-rs migration handling to normalize request-ID prefixes and advance CrossLink’s HRID counters when importing borrowing requests.

Changes:

  • Remove punctuation and whitespace from exported request-ID prefixes.
  • Accept PREFIX-N HRIDs and advance the corresponding broker sequence during import.
  • Update migration documentation and regression tests.
File Description
migration/​scripts.md Documents prefix normalization and import ordering.
migration/​export-crosslink-open-patron-requests.sql Allows numeric HRIDs with a hyphenated separator.
migration/​export-crosslink-directory.sql Normalizes prefixes before validation and export.
migration/​export-crosslink-directory-field-mapping.md Updates prefix mapping rules.
directory/​test/​request_id_prefix_test.go Tests normalized prefixes and invalid values.
broker/​sqlc/​pr_schema.sql Adds the sequence-advancement function to the schema.
broker/​sqlc/​import_query.sql Exposes sequence advancement through SQLC.
broker/​migrations/​080_advance_hrid.up.sql Installs the sequence-advancement function.
broker/​migrations/​080_advance_hrid.down.sql Removes the function on rollback.
broker/​import/​test/​patron_request_test.go Tests borrowing sequence advancement and lending exclusion.
broker/​import/​test/​export_hrid_preflight_test.go Updates accepted and rejected HRID cases.
broker/​import/​db/​repo.go Parses imported borrowing HRIDs and advances their sequences.

Review effort: Balanced

Comment thread broker/import/db/repo.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Locale-dependent character stripping can allow non-ASCII prefixes to bypass validation, producing inconsistent migration results across database locales.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Make punctuation and whitespace removal locale-independent

migration/​export-crosslink-directory.sql:334

PostgreSQL's [:punct:] and [:space:] classes are locale-dependent, not ASCII-only. Under a Unicode-aware locale, a prefix such as ABC— can have its non-ASCII dash removed and pass the subsequent alphanumeric validation, whereas a C-locale database rejects it. This makes migration results depend on the source database's locale and bypasses the documented rejection of non-ASCII characters. Apply the C collation to this replacement so only ASCII punctuation and whitespace are removed.

2 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because a Go-formatting finding passed the severity filter but was omitted from the published review.

No open issues 🎉

Review effort: Balanced

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants