Skip to content

Commit

Permalink
fix tuple elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Jan 31, 2025
1 parent 9262af5 commit 0dc0641
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
8 changes: 4 additions & 4 deletions crates/dojo/types/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl Ty {
}
(Ty::Tuple(t1), Ty::Tuple(t2)) => {
if t1.len() != t2.len() {
Some(Ty::Tuple(t2.clone()))
Some(Ty::Tuple(t1.iter().filter_map(|ty| if !t2.contains(ty) { Some(ty.clone()) } else { None }).collect()))
} else {
// Compare each tuple element recursively
let diff_elements: Vec<Ty> =
Expand All @@ -306,21 +306,21 @@ impl Ty {
if a1 == a2 {
None
} else {
Some(Ty::Array(a2.clone()))
Some(Ty::Array(a1.clone()))
}
}
(Ty::ByteArray(b1), Ty::ByteArray(b2)) => {
if b1 == b2 {
None
} else {
Some(Ty::ByteArray(b2.clone()))
Some(Ty::ByteArray(b1.clone()))
}
}
(Ty::Primitive(p1), Ty::Primitive(p2)) => {
if p1 == p2 {
None
} else {
Some(Ty::Primitive(*p2))
Some(Ty::Primitive(*p1))
}
}
// Different types entirely - we cannot diff them
Expand Down
29 changes: 12 additions & 17 deletions crates/torii/sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,33 +899,28 @@ fn add_columns_recursive(
}
}
Ty::Tuple(tuple) => {
let tuple_diff =
if let Some(upgrade_diff) = upgrade_diff { upgrade_diff.as_tuple() } else { None };
let elements_to_process = if let Some(diff) = upgrade_diff.and_then(|d| d.as_tuple()) {
// Only process elements from the diff
diff.iter().filter_map(|m| {
tuple.iter().position(|member| member == m)
.map(|idx| (idx, m))
}).collect()
} else {
// Process all elements
tuple.iter().enumerate().collect::<Vec<_>>()
};

for (idx, member) in tuple.iter().enumerate() {
for (idx, member) in elements_to_process {
let mut new_path = path.to_vec();
new_path.push(idx.to_string());

let member_diff = if let Some(diff) = tuple_diff {
if let Some((_, m)) =
diff.iter().enumerate().find(|(i, _)| *i == idx && *i >= tuple.len())
{
Some(m)
} else {
continue;
}
} else {
None
};

add_columns_recursive(
&new_path,
member,
columns,
alter_table_queries,
indices,
table_id,
member_diff,
None,
)?;
}
}
Expand Down

0 comments on commit 0dc0641

Please sign in to comment.