Open josephschorr opened 2 years ago
cc @palacerteupgrade @jhalleeupgrade
Great proposal! Thanks for taking the time to write this; it's very thorough.
Based on this, my understanding is that ddl & dml changes aren't separated as of now so it wouldn't be possible to run or output them separately. As a first step, do you think it would be acceptable to only add a CLI command/flag that allows to output the SQL? (ddl + dml) from a certain revision? (mvp)
e.g: spicedb migrate --dry-run
(code would already detect which revisions need to be applied)
Perhaps I'm missing something and it isn't possible to narrow this the way I'm proposing? Please let me know.
Side question: Any reason why you guys decided on implementing the migration process yourselves instead of using something like https://github.com/golang-migrate/migrate ?
As a first step, do you think it would be acceptable to only add a CLI command/flag that allows to output the SQL? (ddl + dml) from a certain revision? (mvp)
We don't have that distinction right now, which would mean changing some of the existing migrations; if we are going to do so, that's about half of the work for the proposal anyway, so it would likely be possible to start with that, but with the caveat that properly handling versions would require re-versioning the migrations yet again
Any reason why you guys decided on implementing the migration process yourselves instead of using something like https://github.com/golang-migrate/migrate ?
It appears to not support migrations that are purely code based, which is a requirement we have
As a first step, do you think it would be acceptable to only add a CLI command/flag that allows to output the SQL? (ddl + dml) from a certain revision? (mvp)
We don't have that distinction right now, which would mean changing some of the existing migrations; if we are going to do so, that's about half of the work for the proposal anyway, so it would likely be possible to start with that, but with the caveat that properly handling versions would require re-versioning the migrations yet again
Any reason why you guys decided on implementing the migration process yourselves instead of using something like https://github.com/golang-migrate/migrate ?
It appears to not support migrations that are purely code based, which is a requirement we have
That makes sense. Thanks for the detailed answer.
A few remaining questions:
Would the cmd only output the SQL by comparing with the current vision running or it would also be able to output the SQL between 2 versions?
e.g: spicedb migrate 1.0.0 1.0.2 --output-only
From looking at the cli changes mentioned in the proposal:
retrieving the statements to execute for a DDL migration
It seems that it isn't planned to include DML changes. However, it seems that there are DML changes which are SQL statements. (e.g backfill_xid_add_indices migration). Is excluding this from the proposal on purpose?
Problem: The SpiceDB datastores occasionally require migrations of the schema and data for the underlying services or engines. For example, adding a new index into Postgres, or writing a default transaction into MySQL.
Currently, this is handled by the
spicedb migrate
command, which executes all migrations up until the specified revision.However, this design has a number of issues:
IsReady()
call on datastores (except MySQL) checks for only the current migration revision: if a revision has moved onward, then it will return false, and if there is a health check based on it (which we do not currently do), it will breakIsReady,
which leads to some duplicationProposal
Update the migration revision system to handle backwards and forwards compatibility, break out DDL and DML migrations and define a means of testing.
DDL vs DML
DDL Revision
DML revision
Tracking Revision
dml_revision
)Updating a DDL revision
Rename the column from its format ID to its current ID
Updating a DML revision
Place the current revision into the
dml_revision
columnChecking the current revision
Select the single row from the table, which grabs both the DML revision and the column name containing the DDL revision
Compatibility
IsReady
will use the revision compatibility portion of the migration revision to determine whether the current code is compatible with the current revisionDefining compatibility
Encoding compatibility
Compatibility will be encoded into a “migration revision and compatibility” string that will be stored for DDL as a column name and DML as the value in the primary key:
{ AtLeast: “6" }
6.8.0-a-6
v6_8_0__a__6
{ AtLeast: “6.1" }
6.8.0-a-6.1
v6_8_0__a__6_1
{ Only: “6.8.0" }
7.0.0-o-6.8.0
v7_0_0__o__6_8_0
Checking compatibility
If SpiceDB sees a revision different from its latest, it will parse the encoded form and determine whether it can continue running against that revision
If it cannot, it will return IsReady false and go unhealthy with an informative error
Testing
Provide a means for defining test data for each step of a migration, to ensure it can be end-to-end tested in CI
CLI changes