mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-24 19:49:43 -05:00
Starting fixes for dolt_schema changes in non-tabular mode
This commit is contained in:
@@ -43,7 +43,6 @@ import (
|
||||
|
||||
type diffOutput int
|
||||
type diffPart int
|
||||
type diffMode int
|
||||
|
||||
const (
|
||||
SchemaOnlyDiff diffPart = 1 // 0b0001
|
||||
@@ -63,7 +62,6 @@ const (
|
||||
SummaryFlag = "summary"
|
||||
whereParam = "where"
|
||||
limitParam = "limit"
|
||||
SQLFlag = "sql"
|
||||
SkinnyFlag = "skinny"
|
||||
MergeBase = "merge-base"
|
||||
DiffMode = "diff-mode"
|
||||
|
||||
@@ -44,6 +44,10 @@ type diffWriter interface {
|
||||
BeginTable(ctx context.Context, td diff.TableDelta) error
|
||||
// WriteSchemaDiff is called to write a schema diff for the table given (if requested by args)
|
||||
WriteSchemaDiff(ctx context.Context, toRoot *doltdb.RootValue, td diff.TableDelta) error
|
||||
// WriteTriggerDiff is called to write a trigger diff
|
||||
WriteTriggerDiff(ctx context.Context, triggerName, oldDefn, newDefn string) error
|
||||
// WriteViewDiff is called to write a view diff
|
||||
WriteViewDiff(ctx context.Context, viewName, oldDefn, newDefn string) error
|
||||
// RowWriter returns a row writer for the table delta provided, which will have Close() called on it when rows are
|
||||
// done being written.
|
||||
RowWriter(ctx context.Context, td diff.TableDelta, unionSch sql.Schema) (diff.SqlRowDiffWriter, error)
|
||||
@@ -181,6 +185,16 @@ func pluralize(singular, plural string, n uint64) string {
|
||||
|
||||
type tabularDiffWriter struct{}
|
||||
|
||||
func (t tabularDiffWriter) WriteTriggerDiff(ctx context.Context, triggerName, oldDefn, newDefn string) error {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (t tabularDiffWriter) WriteViewDiff(ctx context.Context, viewName, oldDefn, newDefn string) error {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
var _ diffWriter = (*tabularDiffWriter)(nil)
|
||||
|
||||
func (t tabularDiffWriter) Close(ctx context.Context) error {
|
||||
@@ -272,6 +286,16 @@ func (t tabularDiffWriter) RowWriter(ctx context.Context, td diff.TableDelta, un
|
||||
|
||||
type sqlDiffWriter struct{}
|
||||
|
||||
func (s sqlDiffWriter) WriteTriggerDiff(ctx context.Context, triggerName, oldDefn, newDefn string) error {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s sqlDiffWriter) WriteViewDiff(ctx context.Context, viewName, oldDefn, newDefn string) error {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
var _ diffWriter = (*tabularDiffWriter)(nil)
|
||||
|
||||
func (s sqlDiffWriter) Close(ctx context.Context) error {
|
||||
@@ -308,6 +332,16 @@ type jsonDiffWriter struct {
|
||||
tablesWritten int
|
||||
}
|
||||
|
||||
func (j *jsonDiffWriter) WriteTriggerDiff(ctx context.Context, triggerName, oldDefn, newDefn string) error {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (j *jsonDiffWriter) WriteViewDiff(ctx context.Context, viewName, oldDefn, newDefn string) error {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
var _ diffWriter = (*tabularDiffWriter)(nil)
|
||||
|
||||
func newJsonDiffWriter(wr io.WriteCloser) (*jsonDiffWriter, error) {
|
||||
@@ -331,8 +365,13 @@ func (j *jsonDiffWriter) BeginTable(ctx context.Context, td diff.TableDelta) err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := iohelp.WriteAll(j.wr, []byte(fmt.Sprintf(jsonDiffTableHeader, td.ToName)))
|
||||
|
||||
tableName := td.FromName
|
||||
if len(tableName) == 0 {
|
||||
tableName = td.ToName
|
||||
}
|
||||
|
||||
err := iohelp.WriteAll(j.wr, []byte(fmt.Sprintf(jsonDiffTableHeader, tableName)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -120,6 +120,44 @@ EOF
|
||||
[[ "$output" =~ "$EXPECTED" ]] || false
|
||||
}
|
||||
|
||||
@test "json-diff: views" {
|
||||
dolt sql <<SQL
|
||||
drop table test;
|
||||
create table test (pk int primary key, c1 int, c2 int);
|
||||
call dolt_add('.');
|
||||
insert into test values (1,2,3);
|
||||
insert into test values (4,5,6);
|
||||
SQL
|
||||
dolt commit -am "First commit"
|
||||
|
||||
dolt sql <<SQL
|
||||
create view v1 as select * from test;
|
||||
SQL
|
||||
dolt commit -Am "Second commit"
|
||||
|
||||
dolt diff -r json HEAD HEAD~
|
||||
run dolt diff -r json HEAD HEAD~
|
||||
|
||||
EXPECTED=$(cat <<'EOF'
|
||||
{"tables":[{"name":"","schema_diff":["DROP TABLE `dolt_schemas`;"],"data_diff":[{"from_row":{"extra":{"CreatedAt":0},"fragment":"create view v1 as select * from test","name":"v1","type":"view"},"to_row":{}}]}]}
|
||||
EOF
|
||||
)
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "$EXPECTED" ]] || false
|
||||
|
||||
dolt diff -r json HEAD~ HEAD
|
||||
run dolt diff -r json HEAD~ HEAD
|
||||
|
||||
EXPECTED=$(cat <<'EOF'
|
||||
{"tables":[{"name":"test","schema_diff":["ALTER TABLE `test` DROP `c2`;","ALTER TABLE `test` ADD `c3` varchar(10);"],"data_diff":[{"from_row":{"c1":2,"c2":3,"pk":1},"to_row":{}},{"from_row":{"c1":5,"c2":6,"pk":4},"to_row":{"c1":100,"pk":4}},{"from_row":{},"to_row":{"c1":8,"c3":"9","pk":7}}]}]}
|
||||
EOF
|
||||
)
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "$EXPECTED" ]] || false
|
||||
}
|
||||
|
||||
@test "json-diff: with table args" {
|
||||
dolt sql -q 'create table other (pk int not null primary key)'
|
||||
dolt add .
|
||||
|
||||
Reference in New Issue
Block a user