use mz_stash_types::upgrade::{objects_v37, objects_v38};
use crate::upgrade::MigrationAction;
use crate::{StashError, Transaction, TypedCollection};
pub async fn upgrade(tx: &Transaction<'_>) -> Result<(), StashError> {
const GID_MAPPING_COLLECTION: TypedCollection<
objects_v37::GidMappingKey,
objects_v37::GidMappingValue,
> = TypedCollection::new("system_gid_mapping");
GID_MAPPING_COLLECTION
.migrate_to(tx, |entries| {
let mut updates = Vec::new();
for (key, value) in entries {
let new_key: objects_v38::GidMappingKey = gid_mapping_key_from(key.clone());
let new_fingerprint = value
.fingerprint
.replace("\"TimestampTz\"", "{\"TimestampTz\":{\"precision\":null}}");
let new_value: objects_v38::GidMappingValue = objects_v38::GidMappingValue {
id: value.id,
fingerprint: new_fingerprint,
};
updates.push(MigrationAction::Update(key.clone(), (new_key, new_value)));
}
updates
})
.await?;
Ok(())
}
fn gid_mapping_key_from(key: objects_v37::GidMappingKey) -> objects_v38::GidMappingKey {
objects_v38::GidMappingKey {
schema_name: key.schema_name,
object_type: key.object_type,
object_name: key.object_name,
}
}