mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-15 10:10:50 -06:00
Updating diff command to support better schema diffs for create and delete tables, and to include data in diff when adding or dropping a table.
This commit is contained in:
@@ -403,12 +403,6 @@ func diffUserTables(ctx context.Context, fromRoot, toRoot *doltdb.RootValue, dAr
|
||||
|
||||
if dArgs.diffOutput == TabularDiffOutput {
|
||||
printTableDiffSummary(td)
|
||||
|
||||
// if we're in standard output mode, follow Git convention
|
||||
// and don't print data diffs for added/dropped tables
|
||||
if td.IsDrop() || td.IsAdd() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if tblName == doltdb.DocTableName {
|
||||
@@ -453,10 +447,6 @@ func diffSchemas(ctx context.Context, toRoot *doltdb.RootValue, td diff.TableDel
|
||||
}
|
||||
|
||||
if dArgs.diffOutput == TabularDiffOutput {
|
||||
if td.IsDrop() || td.IsAdd() {
|
||||
panic("cannot perform tabular schema diff for added/dropped tables")
|
||||
}
|
||||
|
||||
return printShowCreateTableDiff(ctx, td)
|
||||
}
|
||||
|
||||
@@ -469,13 +459,19 @@ func printShowCreateTableDiff(ctx context.Context, td diff.TableDelta) errhand.V
|
||||
return errhand.BuildDError("cannot retrieve schema for table %s", td.ToName).AddCause(err).Build()
|
||||
}
|
||||
|
||||
sqlDb := sqle.NewSingleTableDatabase(td.ToName, fromSch, td.FromFks, td.FromFksParentSch)
|
||||
sqlCtx, engine, _ := sqle.PrepareCreateTableStmt(ctx, sqlDb)
|
||||
fromCreateStmt, err := sqle.GetCreateTableStmt(sqlCtx, engine, td.ToName)
|
||||
var fromCreateStmt = ""
|
||||
if td.FromTable != nil {
|
||||
sqlDb := sqle.NewSingleTableDatabase(td.FromName, fromSch, td.FromFks, td.FromFksParentSch)
|
||||
sqlCtx, engine, _ := sqle.PrepareCreateTableStmt(ctx, sqlDb)
|
||||
fromCreateStmt, err = sqle.GetCreateTableStmt(sqlCtx, engine, td.FromName)
|
||||
}
|
||||
|
||||
sqlDb = sqle.NewSingleTableDatabase(td.ToName, toSch, td.ToFks, td.ToFksParentSch)
|
||||
sqlCtx, engine, _ = sqle.PrepareCreateTableStmt(ctx, sqlDb)
|
||||
toCreateStmt, err := sqle.GetCreateTableStmt(sqlCtx, engine, td.ToName)
|
||||
var toCreateStmt = ""
|
||||
if td.ToTable != nil {
|
||||
sqlDb := sqle.NewSingleTableDatabase(td.ToName, toSch, td.ToFks, td.ToFksParentSch)
|
||||
sqlCtx, engine, _ := sqle.PrepareCreateTableStmt(ctx, sqlDb)
|
||||
toCreateStmt, err = sqle.GetCreateTableStmt(sqlCtx, engine, td.ToName)
|
||||
}
|
||||
|
||||
if fromCreateStmt != toCreateStmt {
|
||||
cli.Println(textdiff.LineDiff(fromCreateStmt, toCreateStmt))
|
||||
@@ -605,8 +601,11 @@ func diffRows(ctx context.Context, td diff.TableDelta, dArgs *diffArgs, vrw type
|
||||
if err != nil {
|
||||
return errhand.BuildDError("cannot retrieve schema for table %s", td.ToName).AddCause(err).Build()
|
||||
}
|
||||
|
||||
if td.IsAdd() {
|
||||
fromSch = toSch
|
||||
} else if td.IsDrop() {
|
||||
toSch = fromSch
|
||||
}
|
||||
|
||||
fromRows, toRows, err := td.GetMaps(ctx)
|
||||
@@ -809,7 +808,6 @@ func createSplitter(ctx context.Context, vrw types.ValueReadWriter, fromSch sche
|
||||
if err != nil {
|
||||
return nil, nil, errhand.BuildDError("Merge failed. Tables with different primary keys cannot be merged.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
} else {
|
||||
unionSch = toSch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user