Skip to content

Commit

Permalink
go/libraries/doltcore/doltdb: root_val.go: Restore ForeignKey TableNa…
Browse files Browse the repository at this point in the history
…mes noms serialization as just strings.
  • Loading branch information
reltuk committed Oct 18, 2024
1 parent 12cb658 commit c175d01
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions go/libraries/doltcore/doltdb/root_val.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,23 @@ func (tn TableName) EqualFold(o TableName) bool {
return strings.EqualFold(tn.Name, o.Name) && strings.EqualFold(tn.Schema, o.Schema)
}

// The ForeignKey struct used to include referenced table names as strings and
// now includes them as TableName structs. LD_1 format repositories serialized
// the ForeignKey struct directly to a noms struct with the string fields. So
// we need to maintain that behavior.
func (tn TableName) MarshalNoms(vrw types.ValueReadWriter) (val types.Value, err error) {
return types.String(tn.Name), nil
}

func (tn TableName) UnmarshalNoms(ctx context.Context, nbf *types.NomsBinFormat, v types.Value) error {
str, ok := v.(types.String)
if !ok {
return fmt.Errorf("could not unmarshal %v to doltdb.TableName; expected only a string.", v)
}
tn.Name = string(str)
return nil
}

// ToTableNames is a migration helper function that converts a slice of table names to a slice of TableName structs.
func ToTableNames(names []string, schemaName string) []TableName {
tbls := make([]TableName, len(names))
Expand Down

0 comments on commit c175d01

Please sign in to comment.