Repository navigation
Catalog verifier: the kernel's part, existence and what the catalog states in columns of its own - #265
Conversation
…f its own context.Database.VerifySchemaKitAsync() reads the database's catalog for every object the model declares and reports each as Present, Missing, Different with what differs, or Unverifiable with the reason. It reads the database and not the migrations history, so it does not depend on which differ scaffolded a migration. Kernel: the report a consumer reads, unmarked; ICatalogProbe in the contract; the planner's reading of a model moved, unchanged, into DeclaredObjects, which the verifier shares. PostgreSQL: probes for PgIndex and PgExclusion over pg_index, pg_class and pg_constraint. An expression key and a condition are not compared here: an object that has one is Unverifiable, never Present (#259). Closes #256 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Review at c3acb44, with an independent second reading. Not merged yet: the checks are green and five changes are asked for. Found sound: every facet a Asked for:
And one sentence on |
The verifier read the consumer's own model and skipped the planner's two refusals for it: a name taken twice (SK1001) and an object that needs one the model does not declare. A declared index under the name of one of EF Core's own was found in that index, on a database EF Core had built alone, and the report was clean. Both refusals now stand beside the model's reading (DeclaredObjects.RequireSound) and both readers ask them. A declared expression is not judged against the catalog's columns: SQL written by hand that is one column in parentheses is a column there, and 5.x's fixture has such an index, which was reported as different. Every failure of the read inside a transaction of the caller's is undone to the savepoint, not the refusal of the catalog alone. Tests for what the reader's query was not asked: a partitioned table, a constraint of the name on another schema's table, a storage parameter's case and number form, a model's default schema. And for what makes a column key and SQL by hand that is that column one object to the planner. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With what the review of #265 changed. The shadow decides what the first slice leaves open: a column where an expression is declared. Its own first read, of the tables' columns, is in a savepoint too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The planner prices the reader's query far above jit_above_cost, and on a server as it is installed PostgreSQL compiled some 260 functions for a query that runs in three milliseconds: 0.7 seconds for every call of the verifier, on 16 and 18. The reader puts the session's setting aside for its own statement and puts it back after, in one batch. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Second review, at 3204f02. The six points of the first review are answered, and I found nothing that blocks. Checked beyond reading the diff, in a scratch copy of the commit: with Two notes that do not block, for #259, which touches the same code:
Still open: the four points under "Decided here" are the maintainer's to confirm. The merge waits for that. |
|
The maintainer confirmed the four points under "Decided here" on 2026-11-29, as written. Merging at 3204f02. |
Closes #256
Problem
Nothing could say whether a database holds what a model declares. A database migrated by a context without
UseSchemaKit(), by a differ a design-time factory put in, or altered by hand has the tables and a migrations history that says the model was applied, and none or other of the declared indexes and constraints. Every guard there is asks the pipeline; none asks the database.Change
Kernel
context.Database.VerifySchemaKitAsync(cancellationToken)and what a consumer reads from it, none of it marked:SchemaVerificationReport(Objects,IsClean,NotPresent),VerifiedObject(entity type, owner, kind, name, table, finding),CatalogFindingas a closed union ofPresent,Missing,DifferentandUnverifiable, andCatalogDifference(facet, declared, found).Differentholds every facet that differs, not the firstSK9001):ICatalogProbe, which a contributor implements on its own class, andCatalogProbeContext(the context's connection, open, and its transaction). A contributor without one isUnverifiablefor each of its objects. The kernel refuses an answer that is not one finding for each objectDeclaredObjects: the planner asks it for both sides of a diff, and the verifier for the context's own design-time model. One declaration is one object in each table it lands on, to bothRequireNamesandRequireDependencies, and the verifier asks both throughRequireSound: a name taken twice (SK1001), and an object that needs one the model does not declare. The planner asks them at the two moments of a diff, as beforePostgreSQL package
PgCatalogreads an index, or a constraint with its index, frompg_index,pg_classandpg_constraint, in one query for all objects of a kind.PgCatalogProbecompares: the table, the access method, uniqueness andNULLS NOT DISTINCT, each key that is a column with its order, operator class and collation, the included columns, the storage parameters by what they mean, whether there is a condition, a constraint's operators and deferral, and whether the index is validPgIndexKey,PgExclusionElement,PgStorageParameter), andCreatewrites the SQL from them. No statement and no stored form changed: the tests that hold the statements verbatim pass as they were. What makes two keys one object did change, in one case: see "Decided here", point 4Unverifiablewith the part named. Comparing them is Catalog verifier: expression keys and conditions, compared through a shadow #259, by the way decided on Catalog verifier: VerifySchemaKitAsync for the PostgreSQL kinds #30 on 2026-11-28 from spike G (Spike G: can the server say what a declared expression is, for the verifier? #255)ux_account_kind_title). A declared column where the catalog has an expression is a difference; the other way round is not compared, soUnverifiablehere and the shadow's to say in Catalog verifier: expression keys and conditions, compared through a shadow #259Unverifiablefor every object. Inside a transaction of the caller's the reading is a savepoint, and every failure is undone to it, not the refusal aloneICatalogProbe's remarks say that a probe has to find out whether the role can see the catalog where the database does not refuse: SQL Server's catalog views leave rows out without an error (for SqlServerIndex: clustered and nonclustered, typed #29)Decided here, for the maintainer to confirm
OnModelCreatingpublic: the statements SchemaKit writes for such a table resolve that wayDifferent(table,kind), notMissingpg.Key(x => x.GranteeId)andpg.Key(x => Sql.Raw<int>("\"GranteeId\""))under one name are one index to the planner, and the same for an element of a constraint:mainscaffolds a drop and a create for a model that changes from one to the other, this branch nothing, both ways. That is what the catalog says: PostgreSQL keeps("GranteeId")as the column, and the two are one index there. What they read still differs, and so does a rename of the column: under the column nothing is written for the index, under the SQL the object is dropped before the rename and created after it, with the SQL as written (which fails with 42703 when it still names the old column, as for any SQL written by hand since A renamed column under SQL written by hand: the migration applies and the model's SQL names a column that is gone #209).ColumnByHandIdentityTestsholds the empty diff, the two statements and the two renames, for a key and for an element. The changelog has it under "Changed"Not in this PR: expressions and conditions (#259), and the verifier in the consumer smoke test, in the live tests' own oracle and in the READMEs (#268). SQL Server and SQLite have no probe; the contract was judged for them and measured on SQLite alone.
Not measured: a migration applied under one
search_pathand verified under another, which by the rule above shows asMissing.After the review, one more commit, found while the next slice asked the verifier after every live migration: the reader's query was compiled by the server's JIT on every call. The planner prices it far above
jit_above_cost, and a server as installed took 0.7 seconds to compile some 260 functions for a query that runs in 3 ms, on 16 and 18. The reader now puts the session'sjitsetting aside for its own statement and puts it back, in one batch (PgCatalog.WithoutJit).The_readers_statement_is_not_compiled_by_the_serverholds it on a session withjit_above_cost = 0, with the statement by itself as the control; with the wrapping taken out the test fails on theJIT:section of the plan. The class's live tests went from about 90 seconds to 7.After the review (the second commit): the refusals the verifier skipped, the expression rule, the savepoint for every failure, the remark for #29, the tests the review named as missing, and point 4 above.
Tests
SchemaVerifierTests, on SQLite with a sample probe written against the public contract, and one more inPublicSurfaceTests. The kernel's 894 tests pass, the integration tests on PostgreSQL 16 and 18 among them.PgCatalogProbeLiveTests, on PostgreSQL 16.15 and 18.1, four inColumnByHandIdentityTests, and two inConsumerCompileTests: a startup check compiles with nothing suppressed, and a class that implementsICatalogProbeis asked forSK9001. The package's 703 tests pass on each server.mainat dd5db80 merged in.main, and were not run again after it: CI's lanes are their run on this commit.Each rule was taken out in turn, alone, and the tests run against it (49 rules before the review and 13 after it; the PostgreSQL ones on 18). What failed:
Unverifiable(madePresent)A_contributor_without_a_probe_is_unverifiable_and_the_report_is_not_clean,Without_a_probe_to_ask_the_database_is_not_reachedAn_answer_that_is_not_one_finding_for_each_object_is_refused, four of its five rowsInside_a_transaction_the_probe_reads_through_itThe_connection_is_closed_again_and_one_that_was_open_stays_open,The_connection_is_closed_when_a_probe_throwsA_model_no_migration_could_be_made_of_is_refused_as_the_planner_refuses_it.Beside_a_runtime_model_the_design_time_model_is_readpasses either way: it is a recordIsCleancountsUnverifiableas cleanA_report_is_clean_only_when_every_object_is_presentand two moreUseSchemaKit()A_context_without_UseSchemaKit_is_refusedDifferentneeds a facet, anUnverifiablea reasonA_difference_names_a_facet_and_an_unverifiable_finding_its_reason, eachAn_index_altered_by_hand_…orA_constraint_altered_by_hand_is_different_with_the_facet_namedThe_default_operator_class_of_a_varchar_is_textsThe_collation_of_a_key_that_states_none_is_its_columnsNULLS NOT DISTINCT, included columns, storage parameters, a parameter the model does not state, a constraint's included columns and parameters, deferralThe_same_index_written_otherwise_is_present, thededuplicate_items=falserowA_condition_that_is_gone_is_differentand two rowsAn_index_a_failed_concurrent_build_left_is_not_presentUnverifiableAn_object_with_an_expression_or_a_condition_is_unverifiable_and_never_present,A_constraint_with_a_condition_is_unverifiable_and_never_presentA_role_that_may_not_read_the_catalog_is_unverifiable_for_every_object, eachAn_index_is_looked_for_in_the_schema_of_its_table,A_table_without_a_schema_is_the_one_the_session_findsWhether_an_operator_class_is_the_default_is_the_servers_word, each; the exact class first fails 42 of 54indoptionthe other way roundA_model_that_takes_a_name_twice_is_refused_as_the_planner_refuses_it,A_model_that_needs_what_it_does_not_declare_is_refused_as_the_planner_refuses_it, and on PostgreSQLA_declaration_under_the_name_of_an_index_of_EF_Cores_own_is_refused_and_not_found_in_it; the names alone and the dependencies alone fail the first and the secondNo_index_of_the_5x_fixture_is_different_or_missing, both rows, andA_column_where_an_expression_is_declared_is_not_taken_for_a_differenceA_read_that_fails_inside_a_transaction_leaves_the_callers_transaction_usable'p'among the tables' kinds;'I'among the indexes'An_index_on_a_partitioned_table_is_found, eachnamed.conrelid = t.oidA_constraint_of_the_name_on_another_schemas_table_is_not_the_declared_oneand two moreA_storage_parameter_that_is_a_word_is_compared_by_what_it_saysand thededuplicate_items='OFF'row; thefillfactor = '070'rowA_models_default_schema_is_where_its_tables_are_looked_for,An_index_is_looked_for_in_the_schema_of_its_tableColumnByHandIdentityTests' fourOne clause is held by no test: in the default-operator-class rule, that only an implicit cast counts. Taken out, nothing fails, and with
regclassandregtypeadded to the types nothing fails either: an index under a class reached by a cast that is not implicit is one the server refuses to make, so no index can show the difference. It is in the query because it is in the server's rule. The test's remarks and CLAUDE.md say so.Four mutations did not compile at first (a local function left unused) and were redone by switching the condition off; their rows above are from the second run.
🤖 Generated with Claude Code