-
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: tracking issue #10203
Labels
Component: Query Serving
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Type: RFC
Request For Comment
Comments
shlomi-noach
added
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Component: Query Serving
Type: RFC
Request For Comment
labels
May 3, 2022
This was referenced May 3, 2022
This was referenced May 5, 2022
This was referenced May 8, 2022
This was referenced May 9, 2022
3 tasks
3 tasks
3 tasks
This was referenced May 10, 2022
3 tasks
3 tasks
This was referenced Aug 18, 2022
3 tasks
3 tasks
This was referenced Dec 27, 2022
This was referenced Jan 24, 2023
3 tasks
3 tasks
This was referenced Mar 6, 2023
4 tasks
This was referenced Apr 13, 2023
4 tasks
5 tasks
5 tasks
5 tasks
5 tasks
This was referenced Jan 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Component: Query Serving
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Type: RFC
Request For Comment
Fashionably late, setting up a tracking issue for
schemadiff
, introduced in #9719.General overview
schemadiff
is avitess
library that manages schema definitions, and is able to present a logical diff between two tables, two views, or two schemas. It does so declaratively, without accessing a MySQL server, and is based onsqlparser
, a core library invitess
.Entities
schemadiff
recognizes these entities:TABLE
VIEW
Tables and views are also entities known to
sqlparser
's AST. The parser can parseCREATE TABLE
orCREATE VIEW
statements into well formed constructs.schemadiff
's main logic is to utilize these well formed constructs, comparing them, manipulating them or validating them.Diffs
At the heart of
schemadiff
is to be able to diff:ALTER TABLE
diffALTER VIEW
diffDROP/ALTER/CREATE TABLE/VIEW
statementsA resulting diff is a well formed construct in itself. e.g. the diff of two tables, if not empty, is a
ALTER TABLE
, represented bysqlparser
's matching AST construct. The diff also attains context to its "from" and "to" entities.Taking a tables diff as the classic example, the diff is an
ALTER TABLE
query that takes a table from one format to another (ignoring table name). The alteration may include:Input and output
schemadiff
reads queries, or statements. Because it does not access a MySQL server, by design, it is fed withCREATE
statements that depict a table, view or schema.SQL can have many formatting options, and a table can be presented in multiple ways (see normalization below). It is advisable to feed
schemadiff
with formal output of aSHOW CREATE TABLE
orSHOW CREATE VIEW
statements.Entity constructs can export their well formed constructs, or they can export their
CREATE
SQL statements. For example, you may export a schema into a list of SQL queries viaToQueries()
or into one big blob of definitions withToSQL()
.Diffs can export their formal constructs, or they can export their SQL statements.
Validation
We require
schemadiff
some validations over the structure of the schema/tables/views. It is unfeasible to run all validations in a declarative aproach. Here are some examples to validationsschemadiff
can do/should do, and some that it can't/won't:Attainable validations:
Validations we will probbaly not attain:
Normalization
schemadiff
needs to be able to normalize a schema. SQL allows equivalent or implicit definitions that present different statements. For example:alter table
toALTER TABLE
NULL
whether or not it specifiesDEFAULT NULL
, assuming no otherDEFAULT
value definedint
issigned
whethersigned
is specified or not, as long asunsigned
isn't specifiedint
and attributes likeunsigned
are lower case in MySQL canonical output and we match that format.Applying diffs
schemadiff
also supports the notion of applying schema changes declaratively, again without a MySQL server. It only supports applying Diffs generated byschemadiff
itself.For example, given a "from" and a "to" tables,
schemadiff
core functionality is to be able to generate aAlterTableEntityDiff
. It is then possible toApply()
that diff onto theCreateTableEntity
"from" table, and get aCreateTableEntity
equivalent to the "to" table.By applying changes logically, and using validations as mentioned above,
schemadiff
is able to catch table definition errors without having to contact a server. For example, it can verify that anALTER TABLE ... ADD KEY ...
only uses existing columns; or, given aALTER TABLE ... DROP COLUMN ...
it can edit or remove keys referencing that column.schemadiff
is work in progress. Linked below this comment are relevant pull requests and issues.The text was updated successfully, but these errors were encountered: