MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / inspect

Function inspect

atomic-core/src/pristine/schema/upgrade.rs:104–238  ·  view source on GitHub ↗
(txn: ReadTransaction)

Source from the content-addressed store, hash-verified

102}
103
104fn 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()),

Callers 2

inspect_schema_upgradeFunction · 0.70
upgrade_schemaFunction · 0.70

Calls 15

check_schema_versionFunction · 0.85
read_versionFunction · 0.85
visit_tablesFunction · 0.85
sortMethod · 0.80
is_noneMethod · 0.80
getMethod · 0.65
valueMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected