diff --git a/webv2/api/schema.go b/webv2/api/schema.go index ae0b2beae..acb68b9f3 100644 --- a/webv2/api/schema.go +++ b/webv2/api/schema.go @@ -495,8 +495,6 @@ func UpdateCheckConstraint(w http.ResponseWriter, r *http.Request) { if err != nil { http.Error(w, fmt.Sprintf("Body Read Error : %v", err), http.StatusInternalServerError) } - println(tableId) - println(reqBody) // internal.ToSpannerCheckConstraintName() sessionState := session.GetSessionState() if sessionState.Conv == nil || sessionState.Driver == "" { @@ -512,15 +510,6 @@ func UpdateCheckConstraint(w http.ResponseWriter, r *http.Request) { return } - // check for if requested data can be migrated to spanner - - // for _, oldCk := range sessionState.Conv.SrcSchema[tableId].CheckConstraints { - // println(oldCk.Name) - // // if newFk.Id == oldFk.Id && newFk.Name != oldFk.Name && newFk.Name != "" { - // // newNames = append(newNames, strings.ToLower(newFk.Name)) - // // } - // } - sp := sessionState.Conv.SpSchema[tableId] sp.CheckConstraint = newCKs diff --git a/webv2/api/schema_test.go b/webv2/api/schema_test.go index 9e7894ea8..7c16744aa 100644 --- a/webv2/api/schema_test.go +++ b/webv2/api/schema_test.go @@ -2541,3 +2541,43 @@ func TestGetAutoGenMapMySQL(t *testing.T) { } } + +func TestUpdateCheckConstraint(t *testing.T) { + sessionState := session.GetSessionState() + sessionState.Driver = constants.MYSQL + sessionState.Conv = internal.MakeConv() + + tableID := "table1" + + expectedCheckConstraint := []ddl.Checkconstraint{ + {Id: "ck1", Name: "check_1", Expr: "(age > 18)"}, + {Id: "ck2", Name: "check_2", Expr: "(age < 99)"}, + } + + checkConstraints := []schema.CheckConstraints{ + {Id: "ck1", Name: "check_1", Expr: "(age > 18)"}, + {Id: "ck2", Name: "check_2", Expr: "(age < 99)"}, + } + + body, err := json.Marshal(checkConstraints) + assert.NoError(t, err) + + req, err := http.NewRequest("POST", "update/cks", bytes.NewBuffer(body)) + assert.NoError(t, err) + + q := req.URL.Query() + q.Add("table", tableID) + req.URL.RawQuery = q.Encode() + + rr := httptest.NewRecorder() + + handler := http.HandlerFunc(api.UpdateCheckConstraint) + + handler.ServeHTTP(rr, req) + + assert.Equal(t, http.StatusOK, rr.Code) + + updatedSp := sessionState.Conv.SpSchema[tableID] + + assert.Equal(t, expectedCheckConstraint, updatedSp.CheckConstraint) +}