Repository navigation
Take a table its upgrade record calls current as unchanged without reading the database [all-db] - #518
Merged
Conversation
…ading the database [all-db] UpgradeOptions.CompareMode is Fast by default: a table whose record in st_table_upgrade is a success of this SchemaFormat with the definition's current schema hash is taken as unchanged without reading the database catalog. The store reads only the table name, status, format and hash of every record, once per instance and row by row; the recorded schemas are not read. Anything else compares in full, and UpgradeCompareMode.Full (db upgrade --full-compare) always does, which finds changes made by hand. A full compare that finds nothing to change records the table, so the next fast compare can rely on it and a record left Upgrading or Failed is corrected. That record is Verified unless this format wrote it: a deployment that changed no table must not refuse a rollback to an older tool, so the format check leaves Verified records out. Dry runs write nothing, and records that cannot be read only cost the shortcut. TableSchemaBuilder.Execute and DatabaseInitializer use it; GetCommandText and CompareToDiff stay full. The test fixture compares in full, because a persistent local database may be changed by hand. PublicAPI: additions only (UpgradeCompareMode, UpgradeOptions.CompareMode, TableUpgradeStatus.Verified, TableUpgradeRecordStore.IsRecordedAsCurrent and TryRecordUnchanged). TableUpgradeStatus gains a member at the end, so existing values keep their numbers. Part of #512
jeff377
enabled auto-merge
November 15, 2026 08:26
|
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.



Part of #512. This is the second step. It uses the records added in #517 to skip comparing tables that have not changed.
What changes
UpgradeOptions.CompareModeisFastby default.st_table_upgrademeets three conditions:SucceededorVerified);SchemaFormat;Fullalways compares. It is the only way to find a change made to a table by hand.db upgrade --full-compareselectsFull.table_name,status,format_versionandschema_hash, row by row with a reader.schema_xmlis never read for this, so a database with thousands of tables stays small in memory.UpgradingorFailedgets corrected.Verifiedunless this format wrote the existing record.Verifiedrecords. Without this, a deployment that changed no table would block rolling back to an older tool.TableSchemaBuilder.ExecuteandDatabaseInitializeruse the fast path.GetCommandTextandCompareToDiffalways compare in full.SharedDatabaseStateusesFull, because a persistent local test database may be changed by hand.SchemaFormatremarks now say the version must also be raised when what a comparison detects changes, since fast compare trusts records written under the current version.db upgradeusage text, the DbManager help, and the CLI table indatabase-settings-guide(en and zh-TW).Measured
These numbers were measured while designing this change, against local containers. The setup was 26 framework tables in 3 databases, averaged over 5 rounds. The last column reads all records of a database in one query, which is the approach this PR implements.
Compatibility
The public API changes are additions only:
UpgradeCompareModeUpgradeOptions.CompareModeTableUpgradeStatus.Verified, added last so existing values keep their numbersTableUpgradeRecordStore.IsRecordedAsCurrentandTryRecordUnchangedBehaviour change: with the default options,
TableSchemaBuilder.Executeanddb upgradeno longer notice a table changed by hand while its record is current. UseFullfor that.Verification
dotnet build Polhem.slnx -c Release: 0 warnings../test.shlocally with all five databases. Everything passes exceptGenerate_iOS_Builds, which fails because the local Xcode does not match the iOS workload; it is unrelated to this change.TryRecordUnchangedon all five databases;TableSchemaBuilderrecording a current table;DatabaseInitializer:Failed,Upgrading, an old format, and a stale hash;--full-compareon the command line.Verifiedstatus.SchemaFormatremarks were incomplete; they are updated as described above.Failedrecord that another process wrote at the same moment. Only the diagnostic text is lost, and the next run compares in full again.DatabaseInitializerkeeps its own record cache. It is not updated when a table is upgraded, which costs at most one extra compare.