Skip to content

Commit

Permalink
Merge pull request #5147 from systeminit/zack/ensure-default-is-not-e…
Browse files Browse the repository at this point in the history
…rased

fix: schemas should be created with lineage_id == id
  • Loading branch information
zacharyhamm authored Dec 17, 2024
2 parents ca21a84 + 233c126 commit 7d3be6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/dal/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ impl Schema {

let workspace_snapshot = ctx.workspace_snapshot()?;

let lineage_id = workspace_snapshot.generate_ulid().await?;
// Lineage id has to match id here, otherwise every new schema will be
// treated as a new node, even though it has the same id
let node_weight =
NodeWeight::new_content(id.into(), lineage_id, ContentAddress::Schema(hash));
NodeWeight::new_content(id.into(), id.into(), ContentAddress::Schema(hash));

workspace_snapshot.add_or_replace_node(node_weight).await?;

Expand Down
5 changes: 3 additions & 2 deletions lib/dal/src/workspace_snapshot/graph/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ impl WorkspaceSnapshotGraphV4 {
if let (Some(source_idx), Some(destination_idx)) = (source_idx, destination_idx)
{
if let EdgeWeightKind::Use { is_default: true } = edge_weight.kind() {
ensure_only_one_default_use_edge(self, source_idx)?;
ensure_only_one_default_use_edge(self, source_idx, destination_idx)?;
}

self.add_edge_inner(
Expand Down Expand Up @@ -1781,14 +1781,15 @@ fn prop_node_indexes_for_node_index(
fn ensure_only_one_default_use_edge(
graph: &mut WorkspaceSnapshotGraphV4,
source_idx: NodeIndex,
destination_idx: NodeIndex,
) -> WorkspaceSnapshotGraphResult<()> {
let existing_default_targets: Vec<NodeIndex> = graph
.edges_directed(source_idx, Outgoing)
.filter(|edge_ref| {
matches!(
edge_ref.weight().kind(),
EdgeWeightKind::Use { is_default: true }
)
) && edge_ref.target() != destination_idx
})
.map(|edge_ref| edge_ref.target())
.collect();
Expand Down

0 comments on commit 7d3be6e

Please sign in to comment.