Skip to content

Refactor constraint deferral to derive table from FK metadata#21

Merged
nafg merged 4 commits intomasterfrom
refactor-deferral
Feb 12, 2026
Merged

Refactor constraint deferral to derive table from FK metadata#21
nafg merged 4 commits intomasterfrom
refactor-deferral

Conversation

@nafg
Copy link
Collaborator

@nafg nafg commented Feb 12, 2026

Summary

  • Replace SelfRefConstraints with ConstraintDeferrer, a general-purpose utility that takes MForeignKey objects directly and derives table names from fkTable (MQName) instead of accepting explicit tableName parameters
  • Move qualifiedTable from CopyAction to SlickProfile as quoteQualified, with an MQName overload that schema-qualifies using the metadata object
  • TableCopier now filters allForeignKeys for self-referencing FKs and passes them to ConstraintDeferrer, separating constraint selection from deferral mechanics

Test plan

  • Unit tests pass (bleep test tests — all 7 suites)
  • Integration tests pass (bleep test integration-tests — requires Docker)
  • Compiles on both Scala 2.13 and Scala 3

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 12, 2026 10:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors how self-referencing FK constraints are temporarily deferred during table copy operations by introducing a general-purpose ConstraintDeferrer that operates directly on MForeignKey metadata, while also centralizing schema-qualified quoting helpers in SlickProfile.

Changes:

  • Replace per-table SelfRefConstraints with a reusable ConstraintDeferrer that defers/restores constraints derived from MForeignKey metadata.
  • Move schema-qualified quoting logic into SlickProfile.quoteQualified, including an MQName overload.
  • Update TableCopier to select self-referencing FKs from cached DbContext.allForeignKeys and delegate deferral to ConstraintDeferrer.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
simple-anonymizer/src/scala/simpleanonymizer/TableCopier.scala Switches self-ref FK selection/deferral to ConstraintDeferrer and refactors sequence reset quoting.
simple-anonymizer/src/scala/simpleanonymizer/SlickProfile.scala Adds quoteQualified helpers (including MQName overload) under SlickProfile.
simple-anonymizer/src/scala/simpleanonymizer/SelfRefConstraints.scala Removes the old table-specific self-ref constraint deferral implementation.
simple-anonymizer/src/scala/simpleanonymizer/CopyAction.scala Uses SlickProfile.quoteQualified instead of CopyAction.qualifiedTable.
simple-anonymizer/src/scala/simpleanonymizer/ConstraintDeferrer.scala Introduces a reusable FK deferral/restoration utility based on MForeignKey metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nafg nafg force-pushed the refactor-deferral branch from 737effd to b2598da Compare February 12, 2026 17:51
nafg and others added 3 commits February 12, 2026 14:42
…etadata

Replace SelfRefConstraints with ConstraintDeferrer, a general-purpose
utility that takes MForeignKey objects directly and derives table names
from fkTable (MQName) instead of accepting explicit tableName parameters.

Move qualifiedTable from CopyAction to SlickProfile as quoteQualified,
with an MQName overload that extracts schema from the metadata object.
The caller (TableCopier) now filters allForeignKeys for self-referencing
FKs and passes them to ConstraintDeferrer, separating constraint
selection from deferral mechanics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
deferAll and restoreDeferrability now return DBIO instead of Future,
using DBIO.traverse to run all ALTERs in a single db.run call (one
connection checkout) and asTry for error recovery at the DBIO level.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nafg nafg force-pushed the refactor-deferral branch from b2598da to e87d16a Compare February 12, 2026 19:43
Copilot AI review requested due to automatic review settings February 12, 2026 19:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

If the by-name body parameter throws synchronously instead of
returning a failed Future, restoreDeferrability would never run.
Future.delegate safely wraps the evaluation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nafg nafg merged commit d0a9336 into master Feb 12, 2026
8 checks passed
@nafg nafg deleted the refactor-deferral branch February 12, 2026 20:06
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

Comments