Bug fixes, new schema diff interface

This commit is contained in:
Zach Musgrave
2022-08-23 10:03:31 -07:00
parent b06faccd94
commit 4e7f392dbd
2 changed files with 33 additions and 4 deletions

View File

@@ -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

View File

@@ -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()
}