Fix SQL Server string type mapping to NVARCHAR#223
Merged
jeremydmiller merged 2 commits intoJasperFx:masterfrom Mar 25, 2026
Merged
Fix SQL Server string type mapping to NVARCHAR#223jeremydmiller merged 2 commits intoJasperFx:masterfrom
jeremydmiller merged 2 commits intoJasperFx:masterfrom
Conversation
Member
|
Hey, I'm going to pull this one in now for 8.10 |
Member
|
No dice, @kakins would you want to try to adjust this? |
Contributor
Author
@jeremydmiller Sorry I was out of the loop for a few days after I found this. Just now circling back. Yeah I haven't jumped very deep into Weasel yet but I can dig a little further and figure out the test issues. |
39f49d2 to
472bb48
Compare
Contributor
Author
|
@jeremydmiller I chewed on this most of yesterday. This may be the least disruptive option. Let me know if you have thoughts/objections. And then the sister PR for Wolverine is linked. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request improves the handling of primary key constraints when altering the type of a primary key column in SQL Server table migrations and rollbacks. The changes ensure that the primary key constraint is dropped before the column type is altered (to avoid SQL errors) and then re-added afterward, both when applying schema updates and when rolling them back. The update also introduces targeted tests to verify the correct order of SQL operations.
This does not modify any default data type mapping, in order to preserve backwards compatibility and avoid forcing unexpected migrations.
The intent here is to facilitate a Wolverine-specific column opt-in override for Saga table PKs, using
nvarchar(100)for the data type instead of the implicitvarchar(100). The override would remediate a SQL server data type mismatch created by Weasel defaults resulting in significant performance issues (see below) while using Wolverine sagas. The opt in would trigger a SQL migration that drops the PK constraint and recreates it using the new data type.Motivation
.NET stringtovarchar(100)in DDL, but Weasel’s own command infrastructure (and SQL Server/Ado.NET defaults) send string parameters asNVarChar.CommandExtensionsTests.cs) assert the parameter type isNVarChar, creating a contradiction with thevarcharcolumn mapping. Found in production with a saga table containing hundreds of thousands of rows. Had to scale Azure SQL Server from 4vcores to 18vcores.Key changes
Primary key constraint handling in migrations and rollbacks:
TableDelta(inTableDelta.cs) to drop the primary key constraint before altering a primary key column's type and to re-add the constraint afterward, both for updates and rollbacks. This is achieved by introducing new helper methods (requiresPrimaryKeyDropBeforeUpdate,requiresPrimaryKeyDropBeforeRollback,writePrimaryKeyUpdates, andwritePrimaryKeyRollback). [1] [2] [3] [4] [5]Expanded and improved tests:
can_patch_existing_primary_key_column_type_change) to ensure that patching a table where the primary key column type is changed works as expected.table_delta_sql_ordering) to verify that the generated SQL for updating a primary key column type change drops the constraint before altering the column and re-adds it afterward.table_delta_rollback_sql_ordering) to verify that the generated SQL for rolling back a primary key column type change follows the correct order: dropping the constraint, altering the column, and re-adding the constraint.