-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
schemadiff: diffing two schemas generates a rich SchemaDiff object #12551
schemadiff: diffing two schemas generates a rich SchemaDiff object #12551
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Good merger with #12565, and the tests we were waiting on exposed a bug, now fixed. |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Ping for review 🙏 @dbussink in particular |
go/mysql/collations/mysqldata.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff here is due to gofmt -s -w ...
. the file is not formatted correctly in main
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I only had minor nits/comments/questions.
Thank you for all of the unit tests! ❤️
go/mathutil/equivalence_relation.go
Outdated
r.classElementsMap[r.classCounter] = []string{element} | ||
r.classCounter++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I take it this is used to enforce order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. As the equivalence relation goes, it's only important that any new element gets its own distinct class-number. So r.classCounter++
ensures the next element is added onto its own distinct class.
The users of the equivalence relation, though, are interested in the order, just so that we have kind of a stable sorting mechanism.
go/vt/schemadiff/schema_diff_test.go
Outdated
{ | ||
iteration := 0 | ||
allPerms := map[string]bool{} | ||
allDiffs := schemaDiff.allDiffs()[:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why you use [:]
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious too! Removed.
go/vt/schemadiff/schema_diff_test.go
Outdated
} | ||
for _, diff := range orderedDiffs { | ||
s := diff.CanonicalStatementString() | ||
// Internal sanity, while we're here: see that the equivalence relation has entries for all diffs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I think as part of the inclusive language effort we're supposed to avoid sanity-check related language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to integrity
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@@ -119,7 +119,7 @@ var tounicode_dec8_swedish_ci = [...]uint16{ | |||
0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00ff, 0x0000, 0x0000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shlomi-noach Any reason why the collations data was updated in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbussink yes! Per #12551 (review), this is just a gofmt
issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only change is to fix the lint warnings, removing the redundant eightbit.UnicodeMapping{}
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbussink yes! Per #12551 (review), this is just a gofmt
issue.
// SchemaDiff calulates a rich diff between this schema and the given schema. It is stronger than Diff(). | ||
// On top of returning the list of diffs that can take this schema into the given schema, this function also | ||
// evaluates the dependencies between those diffs, if any. | ||
func (s *Schema) SchemaDiff(other *Schema, hints *DiffHints) (*SchemaDiff, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to deprecate / remove Diff
? I guess it uses it internally, but should we then rename Diff
to diff
to not export it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I intend to do that, but in a separate PR, to have a grace period of a couple weeks where we can use either.
@@ -231,6 +246,11 @@ func (d *RenameTableEntityDiff) IsEmpty() bool { | |||
return d.Statement() == nil | |||
} | |||
|
|||
// EntityName implements EntityDiff | |||
func (d *RenameTableEntityDiff) EntityName() string { | |||
return d.from.Name() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this deliberately the from
name? Or should it be the to
name? Or does it not matter here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this isn't strictly in-use right now, it is deliberately from
name. This is because the diff operates on the from
table -- so that table is the one being affected by the operation. This is in line with the rest of diff types (with the exception of CREATE
where the affected table is to
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
This is a
schemadiff
enhancement. Previously, when diffing two schemas (viaSchema.Diff(other)
) we'd return a list ofDiff
objects, each of which would represent a single change, .e.g anALTER TABLE
,DROP VIEW
, etc. The diffs order was partly heuristic (DROP VIEW
->DROP TABLE
->ALTER TABLE
->CREATE TABLE
->ALTER VIEW
->CREATE VIEW
) and partly evaluated (order views by dependencies). However, the order was not necessarily applicable.This PR introduces a new
SchemaDiff
function which returns a newSchemaDiff
object:SchemaDiff
is a rich object which includes all diffs between the two schemas, but also:VIEW
andFOREIGN KEY
dependencies.ALTER
operation per table/view. In the future, we may allow a breakdown into granular diffs.SchemaDiff
. This lets the user/automation that getsSchemaDiff
to know whether some migrations may run--in-order
, or if one migration must strictly wait for another to complete.vitess
strategy.The implementation relies heavily on the various
Validate()
functionalities. The order of diffs begins with a heuristic order, which is likely to be the final order in most cases; but it may permute that order in between dependent diffs, if the heuristic order is not linearly valid.Note:
VIEW
column dependencies support is provided in unmerged #12147 ; #12147 works, but we're looking to refactor it and reuse an internal implementation (UPDATE: reimplemented in #12565). The tests are prepared and commented out.Related Issue(s)
Diff()
of schemas ordered by valid dependencies #12028Checklist
Deployment Notes