Skip to content

feat(seed): use FK-safe clear instead of unconditional TRUNCATE - #152

Merged
devlead merged 1 commit into
WCOMAB:mainfrom
devlead:feature/clearTable
Jul 13, 2026
Merged

feat(seed): use FK-safe clear instead of unconditional TRUNCATE#152
devlead merged 1 commit into
WCOMAB:mainfrom
devlead:feature/clearTable

Conversation

@devlead

@devlead devlead commented Jul 13, 2026

Copy link
Copy Markdown
Member

Seed jobs failed when the target table was referenced by foreign keys, because SQL Server does not allow TRUNCATE on referenced tables.

Detect incoming FKs on the target at schema load and choose the clear strategy automatically. When DELETE is required, disable constraints on referencing tables, delete all rows, reseed identity when present, then re-enable constraints. TRUNCATE remains the default when no incoming FKs exist.

  • Add GetReferencingTables query and GetClearTargetTableStatement builder
  • Replace TruncateTargetTable with ClearTargetTable and ClearTargetTableStatement
  • Add optional DeleteInsteadOfTruncateTables per-table config override
  • Expose deleteInsteadOfTruncate in sync job config API
  • Document new setting in README

Seed jobs failed when the target table was referenced by foreign keys,
because SQL Server does not allow TRUNCATE on referenced tables.

Detect incoming FKs on the target at schema load and choose the clear
strategy automatically. When DELETE is required, disable constraints on
referencing tables, delete all rows, reseed identity when present, then
re-enable constraints. TRUNCATE remains the default when no incoming FKs
exist.

- Add GetReferencingTables query and GetClearTargetTableStatement builder
- Replace TruncateTargetTable with ClearTargetTable and ClearTargetTableStatement
- Add optional DeleteInsteadOfTruncateTables per-table config override
- Expose deleteInsteadOfTruncate in sync job config API
- Document new setting in README
@devlead
devlead merged commit ee52ac7 into WCOMAB:main Jul 13, 2026
2 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