C#: a schema name that drifted no longer refuses a record resolved by its schema id
The contract says the name a catalog entry carries is metadata and a schema renamed under a stable id opens in every runtime that holds the id. The C# shape comparison refused any name drift, so a record under a declared old id (the entry carrying another name and a different content hash) or under a renamed stable id could not open. The comparison keeps the slot and type checks; a record resolved by name has the same name by construction. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
da0315e69e
commit
0cef517d83
2 changed files with 18 additions and 5 deletions
|
|
@ -989,11 +989,6 @@ namespace GameCult.Caching
|
|||
var ignoredExtraSlots = new List<int>();
|
||||
var defaultedMissingSlots = new List<int>();
|
||||
|
||||
if (!string.Equals(persisted.SchemaName, local.SchemaName, StringComparison.Ordinal))
|
||||
{
|
||||
errors.Add($"schema name drift '{persisted.SchemaName}' -> '{local.SchemaName}'");
|
||||
}
|
||||
|
||||
var persistedBySlot = persisted.Members.ToDictionary(member => member.Slot);
|
||||
var localBySlot = local.Members.ToDictionary(member => member.Slot);
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ namespace GameCult.Caching.Tests
|
|||
var entry = snapshot.SchemaCatalog.Single();
|
||||
entry.SchemaId = OldId;
|
||||
entry.SchemaName = "tests.legacy_deck";
|
||||
entry.ContentHash = "stale";
|
||||
entry.CompatibleSchemaIds = new[] { OldId };
|
||||
snapshot.Records.Single().SchemaId = OldId;
|
||||
File.WriteAllBytes(path, CultDocumentMessagePackSerialization.SerializeSnapshot(snapshot));
|
||||
|
|
@ -136,6 +137,23 @@ namespace GameCult.Caching.Tests
|
|||
}
|
||||
}
|
||||
|
||||
// The name a catalog entry carries is metadata: a record resolves by its schema id, so a schema renamed under the id the
|
||||
// registered type owns opens, with the entry's content hash no longer matching the type's.
|
||||
[Test]
|
||||
public void ASchemaRenamedUnderTheIdARegisteredTypeOwnsOpens()
|
||||
{
|
||||
var path = Path.Combine(_directory, "renamed.cc");
|
||||
using (var cache = Open(path, Bare))
|
||||
cache.Commit(batch => batch.Upsert(typeof(BareDeck), new BareDeck { Name = "d" }, D));
|
||||
var snapshot = Read(path);
|
||||
snapshot.SchemaCatalog.Single().SchemaName = "tests.renamed_deck";
|
||||
snapshot.SchemaCatalog.Single().ContentHash = "stale";
|
||||
File.WriteAllBytes(path, CultDocumentMessagePackSerialization.SerializeSnapshot(snapshot));
|
||||
|
||||
using var reopened = Open(path, Bare);
|
||||
Assert.That(reopened.Get<BareDeck>(D)!.Name, Is.EqualTo("d"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ARecordUnderAnOldIdNoTypeDeclaresIsNotOpenedByThatSchemaName()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue