Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit 3fc65d7

Browse files
si-bors-ng[bot]stack72zacharyhamm
authored
merge: #3424
3424: feat(sdf-server, dal): Adding an edge for default schema variants at pkg import time r=stack72 a=stack72 Schema / Schema Variant Edges now exist as follows: DEFAULT: Schema -> Uses -> Schema Variant In order to make a schema variant the default for a schema, we need to update the correct edge from Use to Default: UPDATE: Schema -> Default -> Schema Variant Therefore, when we are setting a default schema variant we need to find any existing Default edges and convert them back to uses AND we need to find the existing Use edge between our nodes and change that to be a Default Co-authored-by: stack72 <public@paulstack.co.uk> Co-authored-by: Zachary Hamm <zack@systeminit.com>
2 parents 256791e + 07fb3a7 commit 3fc65d7

19 files changed

Lines changed: 432 additions & 315 deletions

File tree

lib/dal/src/action/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl ActionBatch {
168168
workspace_snapshot
169169
.add_edge(
170170
category_id,
171-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
171+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
172172
id,
173173
)
174174
.await?;

lib/dal/src/action/prototype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl ActionPrototype {
203203
workspace_snapshot
204204
.add_edge(
205205
id,
206-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
206+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
207207
func_id,
208208
)
209209
.await?;

lib/dal/src/action/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl ActionRunner {
247247
workspace_snapshot
248248
.add_edge(
249249
action_batch_id,
250-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
250+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
251251
id,
252252
)
253253
.await?;

lib/dal/src/attribute/prototype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl AttributePrototype {
124124
workspace_snapshot
125125
.add_edge(
126126
id,
127-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
127+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
128128
func_id,
129129
)
130130
.await?;
@@ -230,7 +230,7 @@ impl AttributePrototype {
230230
.edges_directed(attribute_prototype_id, Direction::Outgoing)
231231
.await?
232232
.iter()
233-
.find(|(edge_weight, _, _)| edge_weight.kind() == &EdgeWeightKind::Use)
233+
.find(|(edge_weight, _, _)| edge_weight.kind() == &EdgeWeightKind::new_use())
234234
.map(|(_, _, target_idx)| *target_idx)
235235
.ok_or(AttributePrototypeError::MissingFunction(
236236
attribute_prototype_id,
@@ -249,7 +249,7 @@ impl AttributePrototype {
249249
workspace_snapshot
250250
.add_edge(
251251
attribute_prototype_id,
252-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
252+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
253253
func_id,
254254
)
255255
.await?;

lib/dal/src/attribute/prototype/argument.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl AttributePrototypeArgument {
187187
workspace_snapshot
188188
.add_edge(
189189
id,
190-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
190+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
191191
arg_id,
192192
)
193193
.await?;
@@ -249,7 +249,7 @@ impl AttributePrototypeArgument {
249249
workspace_snapshot
250250
.add_edge(
251251
prototype_arg.id(),
252-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
252+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
253253
func_arg_id,
254254
)
255255
.await?;

lib/dal/src/component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl Component {
292292
workspace_snapshot
293293
.add_edge(
294294
component_category_id,
295-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
295+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
296296
id,
297297
)
298298
.await?;
@@ -301,7 +301,7 @@ impl Component {
301301
workspace_snapshot
302302
.add_edge(
303303
id,
304-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
304+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
305305
schema_variant_id,
306306
)
307307
.await?;

lib/dal/src/func.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl Func {
196196
workspace_snapshot
197197
.add_edge(
198198
func_category_id,
199-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
199+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
200200
id,
201201
)
202202
.await?;
@@ -234,7 +234,7 @@ impl Func {
234234
let func_indices = workspace_snapshot
235235
.outgoing_targets_for_edge_weight_kind(
236236
func_category_id,
237-
EdgeWeightKindDiscriminants::Use,
237+
EdgeWeightKind::new_use().into(),
238238
)
239239
.await?;
240240
let name = name.as_ref();
@@ -384,13 +384,18 @@ impl Func {
384384
let arg_node_idx = workspace_snapshot.get_node_index_by_id(id).await?;
385385

386386
let users = workspace_snapshot
387-
.incoming_sources_for_edge_weight_kind(id, EdgeWeightKind::Use.into())
387+
.incoming_sources_for_edge_weight_kind(id, EdgeWeightKind::new_use().into())
388388
.await?;
389389

390390
let change_set = ctx.change_set_pointer()?;
391391
for user in users {
392392
workspace_snapshot
393-
.remove_edge(change_set, user, arg_node_idx, EdgeWeightKind::Use.into())
393+
.remove_edge(
394+
change_set,
395+
user,
396+
arg_node_idx,
397+
EdgeWeightKind::new_use().into(),
398+
)
394399
.await?;
395400
}
396401

lib/dal/src/func/argument.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl FuncArgument {
193193
workspace_snapshot
194194
.add_edge(
195195
func_id,
196-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
196+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
197197
id,
198198
)
199199
.await?;

lib/dal/src/pkg/import.rs

Lines changed: 63 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ async fn import_schema(
18781878

18791879
let installed_schema_variant_ids = vec![];
18801880
for variant_spec in &schema_spec.variants()? {
1881-
let _variant = import_schema_variant(
1881+
let variant = import_schema_variant(
18821882
ctx,
18831883
change_set_id,
18841884
&mut schema,
@@ -1889,41 +1889,39 @@ async fn import_schema(
18891889
)
18901890
.await?;
18911891

1892-
// if let Some(variant) = variant {
1893-
// installed_schema_variant_ids.push(*variant.id());
1894-
//
1895-
// if let Some(variant_spec_data) = variant_spec.data() {
1896-
// let func_unique_id = variant_spec_data.func_unique_id().to_owned();
1897-
//
1898-
// set_default_schema_variant_id(
1899-
// ctx,
1900-
// change_set_pk,
1901-
// &mut schema,
1902-
// schema_spec
1903-
// .data()
1904-
// .as_ref()
1905-
// .and_then(|data| data.default_schema_variant()),
1906-
// variant_spec.unique_id(),
1907-
// *variant.id(),
1908-
// )
1909-
// .await?;
1910-
//
1911-
// if let Thing::Func(asset_func) =
1912-
// thing_map
1913-
// .get(change_set_pk, &func_unique_id)
1914-
// .ok_or(PkgError::MissingFuncUniqueId(func_unique_id.to_string()))?
1915-
// {
1916-
// create_schema_variant_definition(
1917-
// ctx,
1918-
// schema_spec.clone(),
1919-
// installed_pkg_id,
1920-
// *variant.id(),
1921-
// asset_func,
1922-
// )
1923-
// .await?;
1924-
// }
1925-
// }
1926-
// }
1892+
if let Some(variant) = variant {
1893+
if let Some(variant_spec_data) = variant_spec.data() {
1894+
let _func_unique_id = variant_spec_data.func_unique_id().to_owned();
1895+
1896+
set_default_schema_variant_id(
1897+
ctx,
1898+
change_set_id,
1899+
&mut schema,
1900+
schema_spec
1901+
.data()
1902+
.as_ref()
1903+
.and_then(|data| data.default_schema_variant()),
1904+
variant_spec.unique_id(),
1905+
variant.id(),
1906+
)
1907+
.await?;
1908+
1909+
// if let Thing::Func(asset_func) =
1910+
// thing_map
1911+
// .get(change_set_pk, &func_unique_id)
1912+
// .ok_or(PkgError::MissingFuncUniqueId(func_unique_id.to_string()))?
1913+
// {
1914+
// create_schema_variant_definition(
1915+
// ctx,
1916+
// schema_spec.clone(),
1917+
// installed_pkg_id,
1918+
// *variant.id(),
1919+
// asset_func,
1920+
// )
1921+
// .await?;
1922+
// }
1923+
}
1924+
}
19271925
}
19281926

19291927
Ok((Some(schema.id()), installed_schema_variant_ids))
@@ -1932,40 +1930,36 @@ async fn import_schema(
19321930
}
19331931
}
19341932

1935-
// async fn set_default_schema_variant_id(
1936-
// ctx: &DalContext,
1937-
// change_set_pk: Option<ChangeSetPk>,
1938-
// schema: &mut Schema,
1939-
// spec_default_unique_id: Option<&str>,
1940-
// variant_unique_id: Option<&str>,
1941-
// variant_id: SchemaVariantId,
1942-
// ) -> PkgResult<()> {
1943-
// match (change_set_pk, variant_unique_id, spec_default_unique_id) {
1944-
// (None, _, _) | (Some(_), None, _) | (_, Some(_), None) => {
1945-
// if schema.default_schema_variant_id().is_none() {
1946-
// schema
1947-
// .set_default_schema_variant_id(ctx, Some(variant_id))
1948-
// .await?;
1949-
// }
1950-
// }
1951-
// (Some(_), Some(variant_unique_id), Some(spec_default_unique_id)) => {
1952-
// if variant_unique_id == spec_default_unique_id {
1953-
// let current_default_variant_id = schema
1954-
// .default_schema_variant_id()
1955-
// .copied()
1956-
// .unwrap_or(SchemaVariantId::NONE);
1957-
1958-
// if variant_id != current_default_variant_id {
1959-
// schema
1960-
// .set_default_schema_variant_id(ctx, Some(variant_id))
1961-
// .await?;
1962-
// }
1963-
// }
1964-
// }
1965-
// }
1933+
async fn set_default_schema_variant_id(
1934+
ctx: &DalContext,
1935+
change_set_id: Option<ChangeSetId>,
1936+
schema: &mut Schema,
1937+
spec_default_unique_id: Option<&str>,
1938+
variant_unique_id: Option<&str>,
1939+
variant_id: SchemaVariantId,
1940+
) -> PkgResult<()> {
1941+
match (change_set_id, variant_unique_id, spec_default_unique_id) {
1942+
(None, _, _) | (Some(_), None, _) | (_, Some(_), None) => {
1943+
if schema.get_default_schema_variant(ctx).await?.is_none() {
1944+
schema.set_default_schema_variant(ctx, variant_id).await?;
1945+
}
1946+
}
1947+
(Some(_), Some(variant_unique_id), Some(spec_default_unique_id)) => {
1948+
if variant_unique_id == spec_default_unique_id {
1949+
let current_default_variant_id = schema
1950+
.get_default_schema_variant(ctx)
1951+
.await?
1952+
.unwrap_or(SchemaVariantId::NONE);
19661953

1967-
// Ok(())
1968-
// }
1954+
if variant_id != current_default_variant_id {
1955+
schema.set_default_schema_variant(ctx, variant_id).await?;
1956+
}
1957+
}
1958+
}
1959+
}
1960+
1961+
Ok(())
1962+
}
19691963

19701964
// async fn create_schema_variant_definition(
19711965
// ctx: &DalContext,

lib/dal/src/prop.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl Prop {
555555
.add_ordered_edge(
556556
change_set,
557557
ordered_prop_id,
558-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
558+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
559559
id,
560560
)
561561
.await?;
@@ -564,7 +564,7 @@ impl Prop {
564564
workspace_snapshot
565565
.add_edge(
566566
prop_id,
567-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
567+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
568568
id,
569569
)
570570
.await?;
@@ -573,7 +573,7 @@ impl Prop {
573573
workspace_snapshot
574574
.add_edge(
575575
schema_variant_id,
576-
EdgeWeight::new(change_set, EdgeWeightKind::Use)?,
576+
EdgeWeight::new(change_set, EdgeWeightKind::new_use())?,
577577
id,
578578
)
579579
.await?;
@@ -610,7 +610,7 @@ impl Prop {
610610

611611
let workspace_snapshot = ctx.workspace_snapshot()?;
612612
for maybe_elem_node_idx in workspace_snapshot
613-
.outgoing_targets_for_edge_weight_kind(self.id, EdgeWeightKindDiscriminants::Use)
613+
.outgoing_targets_for_edge_weight_kind(self.id, EdgeWeightKind::new_use().into())
614614
.await?
615615
{
616616
if let NodeWeight::Prop(prop_inner) = workspace_snapshot

0 commit comments

Comments
 (0)