Skip to content

Commit 0a1d183

Browse files
nipunn1313Convex, Inc.
authored andcommitted
Clean up compatibility code for deployment audit log table_names snapshot_import [Land ~ Dec 13th] (#31934)
GitOrigin-RevId: 2e06959c1611ea91b9a656b90961cd67c0f33875
1 parent 3b5a100 commit 0a1d183

File tree

2 files changed

+29
-64
lines changed

2 files changed

+29
-64
lines changed

crates/model/src/deployment_audit_log/types.rs

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use common::{
2424
},
2525
};
2626
use database::LegacyIndexDiff;
27-
use maplit::btreemap;
2827
#[cfg(any(test, feature = "testing"))]
2928
use proptest::prelude::*;
3029
use serde::{
@@ -418,50 +417,24 @@ impl TryFrom<ConvexObject> for DeploymentAuditLogEvent {
418417
},
419418
"clear_tables" => DeploymentAuditLogEvent::ClearTables,
420419
"snapshot_import" => {
421-
let first_entry = match fields.get("table_names") {
422-
Some(ConvexValue::Array(a)) => a.first().cloned(),
423-
v => anyhow::bail!("expected array for table_names, got {v:?}"),
424-
};
425-
let table_names: BTreeMap<_, _> = match first_entry {
426-
None => btreemap!(),
427-
Some(ConvexValue::String(_)) => btreemap!(
428-
ComponentPath::root() => remove_vec_of_strings(&mut fields, "table_names")?
429-
.iter()
430-
.map(|s| TableName::from_str(s))
431-
.try_collect()?,
432-
),
433-
Some(ConvexValue::Object(_)) => remove_vec(&mut fields, "table_names")?
434-
.into_iter()
435-
.map(|v| {
436-
let o: ConvexObject = v.try_into()?;
437-
let mut fields = BTreeMap::from(o);
438-
let component = ComponentPath::deserialize(
439-
remove_nullable_string(&mut fields, "component")?.as_deref(),
440-
)?;
441-
let table_names: Vec<_> =
442-
remove_vec_of_strings(&mut fields, "table_names")?
443-
.iter()
444-
.map(|s| TableName::from_str(s))
445-
.try_collect()?;
446-
anyhow::Ok((component, table_names))
447-
})
448-
.try_collect()?,
449-
_ => anyhow::bail!("Unknown table_names field type"),
450-
};
451-
452-
let first_entry = match fields.get("table_names_deleted") {
453-
Some(ConvexValue::Array(a)) => a.first().cloned(),
454-
v => anyhow::bail!("expected array for table_names, got {v:?}"),
455-
};
456-
let table_names_deleted: BTreeMap<_, _> = match first_entry {
457-
None => btreemap!(),
458-
Some(ConvexValue::String(_)) => btreemap!(
459-
ComponentPath::root() => remove_vec_of_strings(&mut fields, "table_names_deleted")?
460-
.iter()
461-
.map(|s| TableName::from_str(s))
462-
.try_collect()?,
463-
),
464-
Some(ConvexValue::Object(_)) => remove_vec(&mut fields, "table_names_deleted")?
420+
let table_names: BTreeMap<_, _> = remove_vec(&mut fields, "table_names")?
421+
.into_iter()
422+
.map(|v| {
423+
let o: ConvexObject = v.try_into()?;
424+
let mut fields = BTreeMap::from(o);
425+
let component = ComponentPath::deserialize(
426+
remove_nullable_string(&mut fields, "component")?.as_deref(),
427+
)?;
428+
let table_names: Vec<_> =
429+
remove_vec_of_strings(&mut fields, "table_names")?
430+
.iter()
431+
.map(|s| TableName::from_str(s))
432+
.try_collect()?;
433+
anyhow::Ok((component, table_names))
434+
})
435+
.try_collect()?;
436+
let table_names_deleted: BTreeMap<_, _> =
437+
remove_vec(&mut fields, "table_names_deleted")?
465438
.into_iter()
466439
.map(|v| {
467440
let o: ConvexObject = v.try_into()?;
@@ -476,9 +449,7 @@ impl TryFrom<ConvexObject> for DeploymentAuditLogEvent {
476449
.try_collect()?;
477450
anyhow::Ok((component, table_names))
478451
})
479-
.try_collect()?,
480-
_ => anyhow::bail!("Unknown table_names_deleted field type"),
481-
};
452+
.try_collect()?;
482453
DeploymentAuditLogEvent::SnapshotImport {
483454
table_names,
484455
table_count: remove_int64(&mut fields, "table_count")? as u64,

npm-packages/system-udfs/convex/tableDefs/deploymentAuditLogTable.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,21 @@ export const snapshotImport = v.object({
179179
action: v.literal("snapshot_import"),
180180
member_id: v.union(v.int64(), v.null()),
181181
metadata: v.object({
182-
table_names: v.union(
183-
v.array(v.string()),
184-
v.array(
185-
v.object({
186-
component: v.union(v.null(), v.string()),
187-
table_names: v.array(v.string()),
188-
}),
189-
),
182+
table_names: v.array(
183+
v.object({
184+
component: v.union(v.null(), v.string()),
185+
table_names: v.array(v.string()),
186+
}),
190187
),
191188
table_count: v.int64(),
192189
import_mode: snapshotImportMode,
193190
import_format: snapshotImportFormat,
194191
requestor: snapshotImportRequestor,
195-
table_names_deleted: v.union(
196-
v.array(v.string()),
197-
v.array(
198-
v.object({
199-
component: v.union(v.null(), v.string()),
200-
table_names: v.array(v.string()),
201-
}),
202-
),
192+
table_names_deleted: v.array(
193+
v.object({
194+
component: v.union(v.null(), v.string()),
195+
table_names: v.array(v.string()),
196+
}),
203197
),
204198
table_count_deleted: v.int64(),
205199
}),

0 commit comments

Comments
 (0)