Repository navigation
Master-table and sharded tenancy: the tenancy's own AutoCreate picks the apply mode, not only whether to apply - #5692
Merged
Conversation
…the apply mode
MasterTableTenancyOptions.AutoCreate ("override the AutoCreate setting for just
the master tenancy table") and ShardedTenancyOptions.AutoCreate ("override the
AutoCreate setting for the master database tables") only ever decided WHETHER
the master tables were migrated. maybeApplyChanges gated on
`AutoCreate ?? StoreOptions.AutoCreateSchemaObjects` and then applied under
StoreOptions.AutoCreateSchemaObjects regardless, so the override was ignored in
every combination except a store set to None, where Weasel's promotion of an
explicit None apply to CreateOrUpdate happened to produce the documented result.
Use the same value for the gate and for the apply.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 20, 2026
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.
Problem
The master-table and sharded tenancies each have an
AutoCreatesetting for their own lookup tables, and both are documented as an override of the store's setting:MasterTableTenancyOptions.AutoCreate(Weasel): "If set, this will override the AutoCreate setting for just the master tenancy table". Thesample_master_table_multi_tenancysnippet indocs/configuration/multitenancy.mdsays the same: "If set, this will override the database schema rules for only the master tenant table from the parent StoreOptions".ShardedTenancyOptions.AutoCreate: "Override the AutoCreate setting for the master database tables. If null, uses the store's AutoCreateSchemaObjects setting."Both
maybeApplyChangesimplementations use the setting only to decide whether to apply. The apply itself always runs under the store's mode:The documented example uses store
Nonewith tenancyCreateOrUpdate. It works only because Weasel promotes an explicitNoneapply toCreateOrUpdate. Every other combination ignores the override:AutoCreateSchemaObjectsAutoCreateNoneCreateOrUpdateCreateOrUpdate, by theNonepromotionCreateOrUpdateCreateOnlyCreateOrUpdateCreateOnly: any drift throwsSchemaMigrationExceptionCreateOrUpdateCreateOrUpdateCreateOnlyCreateOrUpdate: alters the table, and drops columns it doesn't declareCreateOnlyAllCreateOrUpdateAllCreateOrUpdateCreateOrUpdateAllCreateOrUpdateAllA tenancy set to
Nonedoes skip the apply, as documented; only the mode was wrong.The
Allrow carries the most risk. UnderAll, Weasel drops and recreates a table it cannot alter. For the master table, that removes every tenant's row, which is exactly what a host that set the tenancy toCreateOrUpdatemeant to rule out.The
CreateOnlyrow breaks host startup on upgrade.disabledwas added tomt_tenant_databasesin 8.37.3 and tomt_tenant_assignmentsin #4607. A host whose master table predates that column fails at startup if it runs storeCreateOnlywith tenancyCreateOrUpdate, which is the configuration the override exists for. The cause is thatMartenActivator.StartAsynccallsTenancy.BuildDatabases()before any explicit apply. SoApplyAllDatabaseChangesOnStartup()doesn't help:BuildDatabases()throws first.Fix
Compute
_configuration.AutoCreate ?? _options.AutoCreateSchemaObjectsonce, and use it for both the gate and the apply. The change is the same inMasterTableTenancyandShardedTenancy.Tests
MultiTenancyTests/tenancy_auto_create_override.cshas two facts per tenancy, one per direction. Each starts from the lookup table as it was before thedisabledcolumn: the current shape, built by a first store, withdisabledthen dropped.CreateOrUpdateover storeCreateOnly:BuildDatabases()migrates the table, the column is back, and the table works again (GetTenantAsync/AllDisabledAsyncread the column).CreateOnlyover storeCreateOrUpdate:BuildDatabases()refuses withSchemaMigrationException, as the store's ownCreateOnlydoes for a document table, and the table is left untouched.Red, on unmodified
master(2ece3a9) with only the test file added:Green, with the fix:
Whole
MultiTenancyTestsproject, with the fix (net10.0, PostgreSQL 17): 178 of 183 passed. The 5 that failed are inSingleServerMultiTenancyTestsandsingle_server_explorer_does_not_provision. Each timed out in itsInitializeAsyncwhile dropping its tenant databases, onDROP DATABASEunder the harness'sCommand Timeout=5. Neither class reachesMasterTableTenancyorShardedTenancy. Both pass 17/17 when run on their own, on the same build.Schema and migration
No schema change. Two kinds of host see no difference: a host that leaves the tenancy's
AutoCreateunset, and one that sets it while the store's mode isNone, as in the documented example. A host that setCreateOnlyorAllon the tenancy now gets what it configured. ForCreateOnly, that means a drifted master table makesBuildDatabases()throw, where before it was silently altered under the store's mode.🤖 Generated with Claude Code