Repository navigation
feat: the contributor contract and the declaration store, where a declaration never replaces another - #46
Merged
Conversation
…laration never replaces another The kernel gains the types a declaration and a contributor are made of, and the store a declaration lives in. Nothing turns a declaration into DDL yet: the resolver is #43 and the planner #24. Declarations: ISchemaObject and ISchemaDeclaration<TSelf> with the codec as static abstract members; Declare, Redeclare, GetDeclarations<T>() and FindDeclaration<T>() on EF Core's entity types. One annotation per declaration, CodoMetis:{Owner}:{hash}. The kernel computes the key from what the declaration writes: kind and name for a named declaration, kind and every property that is not operational for an unnamed one. Declare refuses a key that is taken, before it stores anything; Redeclare is the only replacing path. The stored value is JSON written by hand in a fixed order, with the format version v and the resolution epoch r. Nothing is omitted but a null and the reader has no default; an unknown version, a property nothing read and a reader that loses the name or the epoch are refused. Contract: ISchemaContributor and SchemaContributor<TDeclaration, TDescriptor> with Plan and ImpactOf as mandatory members, ISchemaDescriptor with Scope, Name and Dependencies, the closed SchemaChange, Impact, BaseChange, Dependency, NameClaim and SchemaPlacement, ValueList<T>, Operational<T>, and AddSchemaContributor<T>(). All public and experimental (SK9001). Closes #45 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…guards are held by tests that fail without them Findings of the analysis of #46, for #45. A contributor's Read could take a property from the reader and drop it, or put a default in its place: nothing was unread, the header was intact, and the declaration that came out of the snapshot was another one. Read now writes what it built and requires the JSON to equal what was stored. That also refuses a stored value that could not have been stored, such as "r":0. Tests that were missing, each shown to fail without its guard: - every writer method keeps an operational property out of the key (only Boolean was covered), and so does a nested object's operational property - an unnamed declaration that is already on the entity type is refused - a Read that returns another kind is refused Co-Authored-By: Claude Fable 5.2 <[email protected]>
This was referenced Nov 11, 2026
Closed
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.
Closes #45
First slice of #7 and #9, which stay open; each has a dated note saying what is left.
Problem
The host splices what a planner returns, and the only planner is the tests' stand-in. There was no type a declaration could be, nowhere to store one, and no contract a contributor could implement. A consumer could declare nothing.
The store is also where the draft's confirmed defect lived (plan, section 3.4): its identity was
Method|Targets|WhereandDeclarecalledSetAnnotation, so a unique index followed by a plain one over the same column wrote one key twice. The unique index was gone, with no error, and the migration applied clean.Change
All in
src/CodoMetis.EFCore.SchemaKit, public and[Experimental("SK9001")].Declarations (
Declarations/)ISchemaObjectandISchemaDeclaration<TSelf>. The codec is static abstract (OwnerId,Read), so the read model needs no service provider.Declare,Redeclare,GetDeclarations<T>(),FindDeclaration<T>(name)on EF Core's entity types.DeclareandRedeclareask for the wiring stamp first.CodoMetis:{Owner}:{hash}: over kind and name for a named declaration, over kind and every property that is not operational for an unnamed one. The kernel computes it from what the declaration writes; a contributor cannot hash one thing and store another.Declarenever replaces. A key that is taken, on the entity type or earlier in the same call, throws before anything is stored.Redeclareis the only replacing path; it compares results only, so two names can be swapped in one call.{"$kind":…,"v":2,"r":…,"name":…,…}, written by hand in a fixed order throughSchemaJsonWriter. Nothing is omitted but a null, andSchemaJsonReaderhas no default: a method either requires its property or returns null. An unknownv, a property nothing read, and a reader that builds anything but the declaration that was stored are refused.Contract (
Contributors/)ISchemaContributorandSchemaContributor<TDeclaration, TDescriptor>, withPlanandImpactOfabstract.ISchemaDescriptorhasScope,Name,DependenciesandWithName.SchemaChange,Impact,BaseChange,Dependency,NameClaim,SchemaPlacement;ValueList<T>andOperational<T>.AddSchemaContributor<T>(), which adds a contributor to a context's services without touching the two EF services. Two contributors for one owner are refused. A descriptor type that is not a record is refused when its contributor is built.SchemaResolveras whatResolveis handed (table, dialect, a fragment builder). It cannot be derived outside the kernel. Turning paths into SQL is SchemaResolver: paths to columns and SQL, identically on both sides of a diff #43.Decisions taken here, cheap to change until
preview.1$kind), not the owner. An index and a trigger of one name under one owner are two declarations; whether the name is taken twice is the name claims' to say (Validation and diagnostics: name claims across kinds, every finding at once #44).SchemaChange.InPlacecarries no statements. The plan showed both a payload and aSchemaSqlparameter.Planwrites into theSchemaSql, and the base class refuses an answer that disagrees with what was written.CodoMetis:SchemaKit=1stays a mark of presence; the version isvon each declaration. This reverses what I recommended before writing the store: a per-declaration version lets one snapshot hold two formats while it is rewritten.Dependency.WholeTableandDependency.SchemaObject, where the plan saidTableandObject: a case namedTableclashes with theTableparameter of its siblingColumn(CS8866).ISchemaObject.NameComparison, defaulting to ordinal, for the plan's rule that names compare as the provider compares them.AddSchemaContributor<T>(), experimental on a type that is not.Not here: the provider markers and
DeclarePostgres/DeclareSqlServer(#25, #29), so the probeX3waits for them; the 5.x readers (#18, #28); model-level declarations.Tests
Local runs were on SDK
11.0.100-rc.1in a scratch copy; this machine has no released SDK. CI is the run that counts.DeclarationStoreTests, the key also derived independently from the documented identity string.SnapshotRoundTripTestsscaffolds one with EF Core's design-time services, compiles it with Roslyn, loads it and reads the declarations from its model, on Npgsql, SQL Server and SQLite, with quotes, a backslash and a line break in the values.E10.render-a-declaration,X1,X2,X4(a resolver of one's own),M1toM3(PlanandImpactOfare mandatory, andImpactOfanswers every base change),P8, and sixP9probes, one per closed union.Each rule was removed in a scratch copy, and the tests that fail were noted. 35 changes, all fail at least one test:
Declarerefusing a key already on the entity typeA_declaration_that_is_already_there_is_refused_and_the_first_staysDeclarerefusing a repeated key in one callThe_same_declaration_twice_in_one_call_…,Two_declarations_that_differ_only_in_an_operational_option_are_one,Names_are_compared_…Declarebeing all or nothingThe_same_declaration_twice_in_one_call_is_refused_and_nothing_is_storedand two moreDeclare; inRedeclareDeclaring_on_a_model_without_the_stamp_…;Redeclaring_on_a_model_without_the_stamp_…Redeclarerefusing two results on one keyRedeclare_that_would_turn_two_declarations_into_one_…The_same_name_on_two_kinds_is_two_declarationsand both golden keysTwo_declarations_that_differ_only_in_an_operational_option_are_one, the golden keyTwo_unnamed_declarations_that_differ_in_an_option_are_both_keptand two moreNames_are_compared_as_the_database_compares_themfalse; an empty listA_property_that_was_not_written_is_not_given_a_defaultA_property_the_declaration_does_not_read_is_refused(both)A_format_version_this_version_does_not_know_is_refusedReadA_reader_that_loses_the_name_or_the_epoch_is_refusedAn_operator_stays_readable_in_the_stored_text, both golden valuesA_declaration_cannot_write_a_property_the_kernel_writes;A_property_cannot_be_written_twice;A_declaration_that_cannot_be_stored_is_refusedInPlaceneeding a statement; statements needingInPlace; counting only the plan's ownA_plan_whose_answer_and_statements_disagree_is_refused,A_plan_is_judged_by_what_it_wrote_itselfA_descriptor_that_is_not_a_record_is_refused_when_the_contributor_is_builtA_declaration_or_a_descriptor_of_another_contributor_is_refusedTryAddEnumerablein the registrationTwo_contributors_for_one_owner_are_refused;A_registered_contributor_reaches_the_registry_…A_registered_contributor_reaches_the_registry_and_leaves_the_host_as_it_wasOperational<T>ignoring its value;ValueList<T>comparing by elementsprivate protectedconstructorWhat_the_kernel_hands_out_cannot_be_made_outside_itAddSchemaContributorThe_contributor_registration_is_marked_experimentalFindDeclarationrefusing an ambiguous nameThe_same_name_on_two_kinds_is_two_declarationsThe_read_model_is_ordered_by_key_whatever_the_order_of_declarationOne change found a gap. The last one survived at first: EF Core keeps annotations sorted, so a test that compared two orders of declaration with each other could not fail. It now compares with the keys' own order.
After the analysis (3f0ae4e)
An analysis of this branch found no blocker, one silent failure and three guards without a test that fails for them. All four are fixed here; the kernel suite on SDK
11.0.100is at 252.Readthat changes the declaration is refused. A contributor'sReadcould take a property from the reader and drop it, or put a default in its place: nothing was unread, the header was intact, and a unique declaration came out of the snapshot as a plain one.DeclarationCodec.Readnow writes whatReadbuilt and requires its JSON to equal what was stored. A stored value that could not have been stored, such as"r":0, is refused the same way.ReadbuiltA_reader_that_drops_a_property_it_read_is_refusedA_reader_that_returns_another_kind_is_refusedDeclarerefusing a key already on the entity type, for an unnamed declarationAn_unnamed_declaration_that_is_already_there_is_refused_and_the_first_staysStrings,Object,ArrayandOptionalStringin turn (onlyBooleanwas covered)Every_writer_method_keeps_an_operational_property_out_of_the_keyAn_operational_property_of_a_nested_object_is_stored_and_stays_out_of_the_keyis the only one on that pathFindings left for issues of their own: a direct
ISchemaContributorimplementation passes the base class's refusals by (#48), the unnamed key depends on the runtime's Unicode tables through the JSON encoder (#49), the wording of the format-version refusal (#50), a kind that is not checked like an owner (#51), and guards still without a failing test (#52).🤖 Generated with Claude Code