Skip to content

Commit

Permalink
WEOS-1125
Browse files Browse the repository at this point in the history
updated gorm migrate functions
  • Loading branch information
atoniaw committed Feb 4, 2022
1 parent dc15c84 commit cbc575f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,6 @@ func anErrorShouldShowLettingTheDeveloperKnowThatIsPartOfAForeignKeyReference()
}

func removedTheFieldFromTheContentType(user, field, contentType string) error {

loader := openapi3.NewSwaggerLoader()
swagger, err := loader.LoadSwaggerFromData([]byte(openAPI))
if err != nil {
Expand Down Expand Up @@ -1092,6 +1091,9 @@ func removedTheFieldFromTheContentType(user, field, contentType string) error {
}

func theFieldShouldBeRemovedFromTheTable(field, table string) error {
if errs != nil {
return errs
}
apiProjection, err := API.GetProjection("Default")
if err != nil {
return fmt.Errorf("unexpected error getting projection: %s", err)
Expand Down Expand Up @@ -1215,7 +1217,7 @@ func TestBDD(t *testing.T) {
TestSuiteInitializer: InitializeSuite,
Options: &godog.Options{
Format: "pretty",
Tags: "WEOS-1125",
Tags: "~long && ~skipped",
//Tags: "WEOS-1176",
//Tags: "WEOS-1110 && ~skipped",
},
Expand Down
17 changes: 10 additions & 7 deletions projections/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,20 @@ func (p *GORMProjection) Migrate(ctx context.Context, builders map[string]ds.Bui
}

//if column exists in table but not in new schema, alter column

//get columns after db drop
columns, err = p.db.Migrator().ColumnTypes(instance)
if err != nil {
p.logger.Errorf("unable to get columns from table %s with error '%s'", name, err)
}
if deleteConstraintError == nil {
for _, c := range columns {
if !utils.Contains(jsonFields, c.Name()) {
if p.db.Dialector.Name() == "sqlite" {
deleteConstraintError = fmt.Errorf("sqlite column changed")
} else {
deleteConstraintError = p.db.Debug().Migrator().AlterColumn(b, c.Name())
if deleteConstraintError != nil {
p.logger.Errorf("got error updating constraint %s", err)
}
deleteConstraintError = p.db.Debug().Migrator().AlterColumn(b, c.Name())
if deleteConstraintError != nil {
p.logger.Errorf("got error updating constraint %s", err)
}

if deleteConstraintError != nil {
break
}
Expand Down

0 comments on commit cbc575f

Please sign in to comment.