Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-wm-arthur committed Feb 27, 2020
1 parent 959ab9e commit 34b1960
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
10 changes: 5 additions & 5 deletions bats/compatibility/runner.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/bin/bash

if [[ $(git diff --stat) != '' ]]; then
echo "cannot run compatibility tests with git working changes"
exit
fi

function build_dolt() {
pushd "$dolt_dir" > /dev/null || exit
git checkout "$1" > /dev/null
Expand All @@ -31,6 +26,11 @@ function run_bats_tests() {
popd > /dev/null || exit
}

# ensure that we have a clean working change set before we begin
if [[ $(git diff --stat) != '' ]]; then
echo "cannot run compatibility tests with git working changes"
exit
fi

# copy all the test files to take them out of source control
# when we checkout different Dolt releases we don't want to
Expand Down
7 changes: 5 additions & 2 deletions go/libraries/doltcore/schema/encoding/schema_marshaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

// Correct Marshalling & Unmarshalling is essential to compatibility across Dolt versions
// any changes to the fields of Schema or other persisted objects must be append only, no
// fields can ever be removed without break compatibility.
// fields can ever be removed without breaking compatibility.
//
// the marshalling annotations of new fields must have the "omitempty" option to allow newer
// versions of Dolt to read objects serialized by older Dolt versions where the field did not
Expand All @@ -46,6 +46,8 @@ type encodedColumn struct {
TypeInfo encodedTypeInfo `noms:"typeinfo,omitempty" json:"typeinfo,omitempty"`

Constraints []encodedConstraint `noms:"col_constraints" json:"col_constraints"`

// NB: all new fields must have the 'omitempty' annotation. See comment above
}

func encodeAllColConstraints(constraints []schema.ColConstraint) []encodedConstraint {
Expand Down Expand Up @@ -80,7 +82,8 @@ func encodeColumn(col schema.Column) encodedColumn {
col.KindString(),
col.IsPartOfPK,
encodeTypeInfo(col.TypeInfo),
encodeAllColConstraints(col.Constraints)}
encodeAllColConstraints(col.Constraints),
}
}

func (nfd encodedColumn) decodeColumn() (schema.Column, error) {
Expand Down
19 changes: 16 additions & 3 deletions go/libraries/doltcore/schema/encoding/schema_marshaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestNomsMarshalling(t *testing.T) {
validated, err := validateUnmarshaledNomsValue(context.Background(), types.Format_7_18, val)

if err != nil {
t.Fatal("Failed compatibility test")
t.Fatal("Failed compatibility test. Schema could not be unmarshalled with mirror type")
}

if !reflect.DeepEqual(tSchema, validated) {
Expand Down Expand Up @@ -186,9 +186,22 @@ func validateUnmarshaledNomsValue(ctx context.Context, nbf *types.NomsBinFormat,
return sd.decodeSchema()
}

func TestMirroredTypes(t *testing.T) {
realType := reflect.ValueOf(&encodedColumn{}).Elem()
mirrorType := reflect.ValueOf(&testEncodedColumn{}).Elem()
require.Equal(t, mirrorType.NumField(), realType.NumField())

// TODO: create reflection tests to ensure that:
// - no fields in testEncodeColumn have the 'omitempty' annotation
// - no legacy fields in encodeColumn have the 'omitempty' annotation (with whitelist)
// - all new fields in encodeColumn have the 'omitempty' annotation
}

// testEncodedColumn is a mirror type of encodedColumn that helps ensure compatibility between Dolt versions
// fields in this test struct should be added WITHOUT the "omitempty" annotation in order to guarentee that
// all fields are being always being written when encodedColumn is serialized.
//
// Fields in this test struct should be added WITHOUT the "omitempty" annotation in order to guarantee that
// all fields in encodeColumn are always being written when encodedColumn is serialized.
// See the comment above type encodeColumn.
type testEncodedColumn struct {
Tag uint64 `noms:"tag" json:"tag"`

Expand Down

0 comments on commit 34b1960

Please sign in to comment.