Skip to content

Commit

Permalink
merge: #4045
Browse files Browse the repository at this point in the history
4045: fix(dal): ensure that we only export the default schema variant r=stack72 a=stack72

While authoring, you could create 10s of versions of a variant. Our current export code would include them all in the exported module.

We only want to export the default schema variant as that's the most "stable". In the future this will be changed to be the latest locked schema variant

Co-authored-by: stack72 <public@paulstack.co.uk>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Jun 26, 2024
2 parents 558273d + 11cc1a5 commit 959cc7b
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions lib/dal/src/pkg/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,49 +86,42 @@ impl PkgExporter {
ctx: &DalContext,
schema: &Schema,
) -> PkgResult<(SchemaSpec, Vec<FuncSpec>)> {
let variant = SchemaVariant::list_for_schema(ctx, schema.id()).await?;
let mut funcs = vec![];
let schema_is_builtin = schema.is_builtin();

let default_variant = SchemaVariant::get_default_for_schema(ctx, schema.id()).await?;

let mut schema_spec_builder = SchemaSpec::builder();
schema_spec_builder.name(schema.name());
schema_spec_builder.unique_id(schema.id().to_string());

let default_variant_id = schema.get_default_schema_variant_id(ctx).await?;
let mut default_variant_unique_id = None;
let mut category = "".to_string();

for variant in &variant {
let variant = SchemaVariant::get_by_id(ctx, variant.id()).await?;
let variant_is_builtin = variant.is_builtin();
let variant_category = variant.clone().category().to_owned();

let variant_funcs = self.export_funcs_for_variant(ctx, variant.id()).await?;
funcs.extend(variant_funcs);

let variant_spec = self
.export_variant(ctx, &variant, variant_is_builtin)
.await?;
self.variant_map
.insert(variant.id(), variant_spec.to_owned());
if variant_spec.unique_id.is_some() {
if let Some(default_variant_id) = default_variant_id {
if variant.id() == default_variant_id {
category = variant_category;
variant_spec
.unique_id
.clone_into(&mut default_variant_unique_id);
}
}
}

let variant_is_builtin = default_variant.is_builtin();
let variant_category = default_variant.clone().category().to_owned();

let variant_funcs = self
.export_funcs_for_variant(ctx, default_variant.id())
.await?;
funcs.extend(variant_funcs);

let variant_spec = self
.export_variant(ctx, &default_variant, variant_is_builtin)
.await?;
self.variant_map
.insert(default_variant.id(), variant_spec.to_owned());
if variant_spec.unique_id.is_some() {
variant_spec
.unique_id
.clone_into(&mut default_variant_unique_id);

schema_spec_builder.variant(variant_spec);
}

let mut data_builder = SchemaSpecData::builder();
data_builder.name(schema.name());
data_builder.ui_hidden(schema.ui_hidden());
data_builder.category(category.clone());
data_builder.category(variant_category.clone());
if let Some(default_unique_id) = default_variant_unique_id {
data_builder.default_schema_variant(default_unique_id);
}
Expand Down

0 comments on commit 959cc7b

Please sign in to comment.