(txn: ReadTransaction)
| 102 | } |
| 103 | |
| 104 | fn inspect(txn: ReadTransaction) -> PristineResult<SchemaUpgradeReport> { |
| 105 | check_schema_version(&txn)?; |
| 106 | super::check_required_capabilities(&txn)?; |
| 107 | let schema_version = match txn.open_table(ATOMIC_META) { |
| 108 | Ok(meta) => meta |
| 109 | .get(SCHEMA_VERSION_KEY)? |
| 110 | .map(|value| { |
| 111 | // check_schema_version has already checked the representation. |
| 112 | u64::from_le_bytes(value.value().try_into().expect("checked schema version")) |
| 113 | }) |
| 114 | .unwrap_or(BASE_SCHEMA_VERSION), |
| 115 | Err(TableError::TableDoesNotExist(_)) => BASE_SCHEMA_VERSION, |
| 116 | Err(error) => return Err(error.into()), |
| 117 | }; |
| 118 | let mut visitor = Inspect { |
| 119 | txn: &txn, |
| 120 | report: SchemaUpgradeReport { |
| 121 | schema_version, |
| 122 | supported_schema_version: SCHEMA_VERSION, |
| 123 | build_version: BUILD_VERSION.into(), |
| 124 | created_with: build_metadata::read_version(&txn, CREATED_WITH_KEY)?, |
| 125 | migrated_with: build_metadata::read_version(&txn, MIGRATED_WITH_KEY)?, |
| 126 | tables_to_add: Vec::new(), |
| 127 | tables_added: Vec::new(), |
| 128 | deferred_tables: Vec::new(), |
| 129 | blockers: Vec::new(), |
| 130 | warnings: Vec::new(), |
| 131 | }, |
| 132 | }; |
| 133 | visit_tables(&mut visitor)?; |
| 134 | let mut report = visitor.report; |
| 135 | report.tables_to_add.sort(); |
| 136 | report.deferred_tables.sort(); |
| 137 | if report |
| 138 | .tables_to_add |
| 139 | .iter() |
| 140 | .any(|name| name == "pending_untracks") |
| 141 | { |
| 142 | report.warnings.push( |
| 143 | "Missing PENDING_UNTRACKS will be initialized empty. Table absence cannot distinguish a legacy database from prior data loss; lost pending-untrack intent cannot be reconstructed.".into(), |
| 144 | ); |
| 145 | } |
| 146 | // A partly lost dependency index is not an additive migration. Even without |
| 147 | // completion rows, an empty replacement reverse index could hide dependents. |
| 148 | if report.tables_to_add.iter().any(|name| { |
| 149 | matches!( |
| 150 | name.as_str(), |
| 151 | "change_deps" | "rev_change_deps" | "change_deps_indexed" |
| 152 | ) |
| 153 | }) { |
| 154 | let has_rows = match txn.open_table(CHANGE_DEPS_INDEXED) { |
| 155 | Ok(table) => !table.is_empty()?, |
| 156 | Err(TableError::TableDoesNotExist(_)) => false, |
| 157 | Err(error) => return Err(error.into()), |
| 158 | } || match txn.open_multimap_table(CHANGE_DEPS) { |
| 159 | Ok(table) => !table.is_empty()?, |
| 160 | Err(TableError::TableDoesNotExist(_)) => false, |
| 161 | Err(error) => return Err(error.into()), |
no test coverage detected