Skip to content

Add exact-byte unique indexes for context, link, and resource link ids - #401

Merged
csev merged 1 commit into
masterfrom
natural-key-course-indexes
Nov 22, 2026
Merged

csev merged 1 commit into
masterfrom
natural-key-course-indexes

Conversation

@csev

@csev csev commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add stored exact-byte columns and unique indexes for context_key, link_key, and resource_link_id, beside the existing sha256 uniques.
  • The upgrade uses the same natural-key loop and still returns 202611220002, so the next php admin/upgrade.php applies it without a version bump.
  • Duplicate examples no longer assume lti_link has a key_id column.

Test plan

  • Run php admin/upgrade.php on a database whose three columns are already varchar(255) ascii_bin
  • Confirm each column logs 0 duplicate groups and added unique
  • Run the upgrade again and confirm the column and unique are already present
  • Local MAMP run: 48 contexts, 470 links, 19 content rows, then a clean second run

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • LTI context, link, and resource-link identifiers now use exact matching, improving consistency when enforcing uniqueness.
    • Database upgrades validate identifier values and existing duplicates before applying the updated uniqueness rules, and report conflicts that prevent migration.
  • Chores
    • Upgrades remove leftover inbound-registration database structures when present. Any remaining rows are reported before the related table is removed.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The LTI schema adds exact-byte unique constraints for context_key, link_key, and resource_link_id. Natural-key migration handling now includes these columns, and tests cover their null and length limits.

Changes: LTI natural identity constraints

Layer / File(s) Summary
Identity schema and migration declarations
lib/src/Services/Admin/AdminService.php, lib/src/Services/Lti/database.php
The natural-key migration specifications include context_key, link_key, and resource_link_id as non-null 255-character columns. The schema adds generated binary columns and unique constraints for exact-byte identity matching alongside the existing hash-based constraints.
Migration checks and validation
lib/src/Services/Lti/database.php, lib/tests/Services/Admin/AdminServiceNaturalKeyTest.php
Natural-key migration handling includes the three columns and avoids referencing key_id in duplicate diagnostics when the table lacks that column. The upgrade also removes leftover inbound-registration schema when present. Tests check null rejection and the specified 255- and 256-character limits.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • tsugiproject/tsugi#400: Adds natural-key unique indexes for other LTI identity tables and introduces the migration loop used by this PR.
  • tsugiproject/tsugi#393: Establishes the varchar(255) ascii_bin column type contract used by this PR.
Merge Risk: Minimal · up to fe6b3

This change adds exact-byte unique indexes for context, link, and resource link ids and extends the natural-key upgrade to cover them. No concrete merge-blocking risk was found. Running the upgrade on a real database before release would still be prudent.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Add exact-byte unique indexes for context, link, and resource link ids" matches the main change. The raw summary and objectives both describe stored exact-byte columns and unique indexes fo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Add exact-byte unique indexes for context, link, and resource link ids" matches the main change. The raw summary and objectives both describe stored exact-byte columns and unique indexes for context_key, link_key, and resource_link_id. The title is specific and concise, and it does not describe anything absent from the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7c002d0 and fe6b316.

Files selected for processing: 3

  • lib/src/Services/Admin/AdminService.php
  • lib/src/Services/Lti/database.php
  • lib/tests/Services/Admin/AdminServiceNaturalKeyTest.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@csev
csev merged commit da8e8c4 into master Nov 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant