diff --git a/compose/internal/repository/module.go b/compose/internal/repository/module.go index 9ab054cb4..d86c48033 100644 --- a/compose/internal/repository/module.go +++ b/compose/internal/repository/module.go @@ -5,7 +5,6 @@ import ( "fmt" "time" - "github.com/davecgh/go-spew/spew" "github.com/jmoiron/sqlx" "github.com/pkg/errors" "github.com/titpetric/factory" @@ -159,6 +158,12 @@ func (r module) updateFields(moduleID uint64, ff types.ModuleFieldSet) error { if e := existing.FindByID(f.ID); e != nil { f.CreatedAt = e.CreatedAt f.UpdatedAt = &now + + // We do not have any other code in place that would handle changes of field name and kind, so we need + // to reset any changes made to the field. + // @todo remove when we are able to handle field rename & type change + f.Name = e.Name + f.Kind = e.Kind } else { f.ID = 0 } @@ -172,7 +177,6 @@ func (r module) updateFields(moduleID uint64, ff types.ModuleFieldSet) error { f.ModuleID = moduleID f.Place = idx f.DeletedAt = nil - spew.Dump(f) if err := r.db().Replace(r.tableFields(), f); err != nil { return errors.Wrap(err, "Error updating module fields") diff --git a/compose/internal/repository/module_test.go b/compose/internal/repository/module_test.go index 4649965ab..da9a173a0 100644 --- a/compose/internal/repository/module_test.go +++ b/compose/internal/repository/module_test.go @@ -39,13 +39,13 @@ func TestModule_updateFields(t *testing.T) { test.NoError(t, err, "unexpected error on module creation") test.Assert(t, len(m.Fields) == 2, "expecting to find two fields in the new module") - m.Fields[0].Name = "one-v2" + m.Fields[0].Name = "one-should-not-be-renamed" m.Fields[1] = &types.ModuleField{Name: "three"} m, err = repo.Update(m) test.NoError(t, err, "unexpected error on module update") test.Assert(t, len(m.Fields) == 2, "expecting to find two fields in the new module") - test.Assert(t, m.Fields[0].Name == "one-v2", "expecting to find field 'one'") + test.Assert(t, m.Fields[0].Name == "one", "expecting to find field 'one', got %q", m.Fields[0].Name) test.Assert(t, m.Fields[0].Place == 0, "expecting Place=0") test.Assert(t, m.Fields[1].Name == "three", "expecting to find field 'three'") test.Assert(t, m.Fields[1].Place == 1, "expecting Place=1")