formatDiff produces a simple line-based diff between two strings.
(labelA, labelB, a, b string)
| 422 | |
| 423 | // formatDiff produces a simple line-based diff between two strings. |
| 424 | func formatDiff(labelA, labelB, a, b string) string { |
| 425 | linesA := strings.Split(a, "\n") |
| 426 | linesB := strings.Split(b, "\n") |
| 427 | |
| 428 | var out strings.Builder |
| 429 | maxLines := len(linesA) |
| 430 | if len(linesB) > maxLines { |
| 431 | maxLines = len(linesB) |
| 432 | } |
| 433 | |
| 434 | for i := 0; i < maxLines; i++ { |
| 435 | var lineA, lineB string |
| 436 | if i < len(linesA) { |
| 437 | lineA = linesA[i] |
| 438 | } |
| 439 | if i < len(linesB) { |
| 440 | lineB = linesB[i] |
| 441 | } |
| 442 | if lineA != lineB { |
| 443 | if lineA != "" { |
| 444 | _, _ = fmt.Fprintf(&out, " - (%s) %s\n", labelA, lineA) |
| 445 | } |
| 446 | if lineB != "" { |
| 447 | _, _ = fmt.Fprintf(&out, " + (%s) %s\n", labelB, lineB) |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | return out.String() |
| 452 | } |
| 453 | |
| 454 | // updateMigrationTracking connects to the running server's |
| 455 | // database and captures current migration state. Called after |
no test coverage detected