Skip to content

Enhance SQL Server saga storage configuration for nvarchar identity columns#2348

Merged
jeremydmiller merged 3 commits intoJasperFx:mainfrom
kakins:sqlserver-nvarchar-saga-id-fix
Mar 27, 2026
Merged

Enhance SQL Server saga storage configuration for nvarchar identity columns#2348
jeremydmiller merged 3 commits intoJasperFx:mainfrom
kakins:sqlserver-nvarchar-saga-id-fix

Conversation

@kakins
Copy link
Copy Markdown
Contributor

@kakins kakins commented Mar 25, 2026

This pull request introduces an opt-in feature to address SQL Server performance issues for string-identified sagas in Wolverine's lightweight saga storage. By default, saga tables use a varchar(100) primary key for string IDs, but this can cause significant performance issues due to implicit conversions with ADO.NET's default nvarchar parameter binding, resulting in full table scans for saga table oprerations.

The new option allows users to explicitly use nvarchar(100) for string IDs, avoiding these issues. The update includes changes to configuration APIs, schema generation logic, documentation, and adds tests to verify the new behavior.

TODO: Pending Weasel version update from JasperFx/weasel#223

SQL Server string saga ID schema improvements:

  • Added a useNVarCharForStringId parameter to AddSagaType methods in SagaConfigurationExtensions, allowing users to opt in to nvarchar(100) for string saga IDs instead of the default varchar(100) in SQL Server. [1] [2]
  • Updated SagaTableDefinition to store the UseNVarCharForStringId flag and pass it through to schema generation.
  • Modified DatabaseSagaSchema to generate the primary key column as nvarchar(100) when the option is enabled and the ID type is string.

Testing and validation:

  • Added comprehensive tests in string_identity_schema_configuration.cs to verify default and opt-in behaviors, schema migration, and delta detection for both varchar and nvarchar configurations.

Documentation updates:

  • Updated the durability and saga documentation to explain the new option, its rationale, and usage instructions, including warnings about schema migrations when enabling the feature on existing databases. [1] [2]

…or nvarchar identity columns and updating related documentation and tests
@jeremydmiller
Copy link
Copy Markdown
Member

@kakins I think we could take this in when you're ready. I interpret "Ready for Review" as not really ready, so you tell me

@kakins kakins marked this pull request as ready for review March 25, 2026 20:23
@kakins
Copy link
Copy Markdown
Contributor Author

kakins commented Mar 25, 2026

@jeremydmiller Yeah I think this is ready if you don't have many issues with it. The only thing pending was the Weasel package update. Once that new version is out there I can update the version here and retest.

@kakins
Copy link
Copy Markdown
Contributor Author

kakins commented Mar 26, 2026

@jeremydmiller I didn't notice the Weasel packages were already published. Updated now. Investigating test failures.

@kakins
Copy link
Copy Markdown
Contributor Author

kakins commented Mar 27, 2026

@jeremydmiller Test passing. Thanks for re-running.

@jeremydmiller jeremydmiller merged commit e65dd1b into JasperFx:main Mar 27, 2026
18 of 20 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.

2 participants