I have…
- Read the following guideline: Troubleshooting and Support | Squidex. I understand that my support request might get deleted if I do not follow the guideline.
- Used code blocks with ``` to format my code examples like JSON or logs properly.
I’m submitting a…
- Regression (a behavior that stopped working in a new release)
- Bug report
- Performance issue
- Documentation issue or request
Current behavior
When executing CLI command “sq schemas sync {schema-name}” whilst trying to migrate schema definitions from one self-hosted instance of Squidex to another I noticed that any schema that included a component reference was being migrated but losing that component reference.
Expected behavior
Component references in exported schema definitions (json) would be respected and recreated, looking up schema ID from the referenced component name.
Minimal reproduction of the problem
As stated above.
Environment
Non-prod.
App Name: the-event-app
- Self hosted with docker
- Self hosted with IIS
- Self hosted with other version
- Cloud version
Version: CLI version 13.7
Browser:
- Chrome (desktop)
- Chrome (Android)
- Chrome (iOS)
- Firefox
- Safari (desktop)
- Safari (iOS)
- IE
- Edge
Others:
I took a look at the code directly, and got it working by changing the Squidex.CLI.Commands.Models.SchemaWithRefsExtensions.AdjustReferences method to the below. But I am not set up to raise a PR and not very aware of any potential wider implications.
public static SchemaWithRefs<T> AdjustReferences<T>(this SchemaWithRefs<T> target, ICollection<SchemaDto> allSchemas) where T : UpsertSchemaDto
{
List<string>? Handle(List<string>? schemaIds)
{
if (schemaIds?.Count > 0)
{
var newSchemaIds = schemaIds.ToList();
var i = 0;
foreach (var schemaId in schemaIds)
{
if (target.ReferencedSchemas.TryGetValue(schemaId, out var name))
{
var referenced = allSchemas.FirstOrDefault(x => x.Name == name);
if (referenced != null)
{
newSchemaIds[i] = referenced.Id;
}
}
i++;
}
return newSchemaIds;
}
return null;
}
foreach (var field in target.Schema.Fields.OrEmpty())
{
switch (field.Properties)
{
case ReferencesFieldPropertiesDto reference:
reference.SchemaIds = Handle(reference.SchemaIds);
break;
case ComponentsFieldPropertiesDto componentsReference:
componentsReference.SchemaIds = Handle(componentsReference.SchemaIds);
break;
case ComponentFieldPropertiesDto componentReference:
componentReference.SchemaIds = Handle(componentReference.SchemaIds);
break;
}
foreach (var nested in field.Nested.OrEmpty())
{
switch (nested.Properties)
{
case ReferencesFieldPropertiesDto reference:
reference.SchemaIds = Handle(reference.SchemaIds);
break;
case ComponentsFieldPropertiesDto componentsReference:
componentsReference.SchemaIds = Handle(componentsReference.SchemaIds);
break;
case ComponentFieldPropertiesDto componentReference:
componentReference.SchemaIds = Handle(componentReference.SchemaIds);
break;
}
}
}
return target;
}