diff --git a/go/libraries/doltcore/diff/diff.go b/go/libraries/doltcore/diff/diff.go index 4250cce468..01bbd98769 100755 --- a/go/libraries/doltcore/diff/diff.go +++ b/go/libraries/doltcore/diff/diff.go @@ -57,7 +57,7 @@ type RowDiffer interface { Close() error } -// SqlRowDiffWriter knows how to write diff rows to an arbitrary format and destination. +// SqlRowDiffWriter knows how to write diff rows for a table to an arbitrary format and destination. type SqlRowDiffWriter interface { // WriteRow writes the diff row given, of the diff type provided. colDiffTypes is guaranteed to be the same length as // the input row. @@ -67,5 +67,16 @@ type SqlRowDiffWriter interface { Close(ctx context.Context) error } +// SchemaDiffWriter knows how to write SQL DDL statements for a schema diff for a table to an arbitrary format and +// destination. +type SchemaDiffWriter interface { + // WriteSchemaDiff writes the schema diff given (a SQL statement) and returns any error. A single table may have + // many SQL statements for a single diff. + WriteSchemaDiff(ctx context.Context, schemaDiffStatement string) error + + // Close finalizes the work of this writer. + Close(ctx context.Context) error +} + // ColorFunc is a function that can color a format string type ColorFunc func(a ...interface{}) string diff --git a/go/libraries/doltcore/table/typed/json/json_diff_writer.go b/go/libraries/doltcore/table/typed/json/json_diff_writer.go index c313f0ece4..e36a6b3c47 100755 --- a/go/libraries/doltcore/table/typed/json/json_diff_writer.go +++ b/go/libraries/doltcore/table/typed/json/json_diff_writer.go @@ -35,10 +35,15 @@ func NewJsonDiffWriter(wr io.WriteCloser, outSch schema.Schema) (*JsonDiffWriter // leading diff type column with empty name cols := outSch.GetAllCols() newCols := schema.NewColCollection() - newCols.Append(schema.NewColumn("diff_type", 0, types.StringKind, false)) - newCols.Append(cols.GetColumns()...) + newCols = newCols.Append(schema.NewColumn("diff_type", 0, types.StringKind, false)) + newCols = newCols.AppendColl(cols) - writer, err := NewJSONWriter(wr, outSch) + newSchema, err := schema.SchemaFromCols(newCols) + if err != nil { + return nil, err + } + + writer, err := NewJSONWriter(wr, newSchema) if err != nil { return nil, err } @@ -77,3 +82,16 @@ func (j *JsonDiffWriter) WriteRow( func (j *JsonDiffWriter) Close(ctx context.Context) error { return j.wr.Close(ctx) } + type JsonSchemaDiffWriter struct { + wr io.WriteCloser + } + +var _ diff.SchemaDiffWriter = (*JsonSchemaDiffWriter)(nil) + +func (j JsonSchemaDiffWriter) WriteSchemaDiff(ctx context.Context, schemaDiffStatement string) error { + return nil +} + +func (j JsonSchemaDiffWriter) Close(ctx context.Context) error { + return j.wr.Close() +}