contentful-cli
contentful-cli copied to clipboard
Generated migration files swap field controls based on alpha order and field definition order
Expected Behavior
When creating a migration script with:
contentful merge export
...or through the Merge app UI...
I expect the field controls for content type fields to match what was selected in the UI.
Actual Behavior
Field controls are assigned to fields in alphabetical order based on the order the fields were defined in. Running an incorrectly generated migration results in a broken content type.
function migrationFunction(migration, context) {
const testType = migration.createContentType("testType");
testType
.displayField("cField")
.name("TestType")
.description("")
const testTypeAField = testType.createField("aField");
testTypeAField
.name("A - Field")
.type("Integer")
.localized(false)
.required(false)
.validations([])
.disabled(false)
.omitted(false)
const testTypeCField = testType.createField("cField");
testTypeCField
.name("C - Field")
.type("Symbol")
.localized(false)
.required(false)
.validations([])
.disabled(false)
.omitted(false)
const testTypeBField = testType.createField("bField");
testTypeBField
.name("B - Field")
.type("Date")
.localized(false)
.required(false)
.validations([])
.disabled(false)
.omitted(false)
testType.changeFieldControl("aField", "builtin", "numberEditor" // aField is first alphabetically so correctly gets the numberEditor
testType.changeFieldControl("cField", "builtin", "datePicker") // cField is third alphabetically so incorrectly gets the datePicker from the third field defined (bField)
testType.changeFieldControl("bField", "builtin", "singleLine") // bField is second alphabetically so incorrectly gets the singleLine from the second field defined (cField)
}
module.exports = migrationFunction;
Possible Solution
Steps to Reproduce
- Create a model with field names that aren't alphabetical i.e.
A - Field, C - Field, B - Field
. - Choose different field types for each field to demonstrate the issue
- Generate a migration script with
contentful merge export
- See that the
changeFieldControl
function calls are incorrect.
Context
I'm new to the CLI but this doesn't give me much confidence in the tooling.
Environment
- Language Version: v18.16.1
- Package Manager Version: 9.5.1
- Browser Version: n/a
- Operating System: MacOS 13.4.1
- Package Version: 2.6.30
Hey @ecline123, thanks for reporting this. I can confirm that this is a bug we are working on at the moment, will update you once this is fixed.
@ruderngespra Any progress on this?
@ecline123 Hey, hey, yes, we have now updated the related migration script creation logic. Could you let me know if you are still running into this?