edgedb-cli
edgedb-cli copied to clipboard
Data migrations in interactive mode
https://github.com/edgedb/edgedb/pull/2138
-
We should allow inserting arbitrary queries:
y - confirm the prompt, use the DDL statements n - reject the prompt l - list the DDL statements associated with prompt c - list already confirmed EdgeQL statements i - insert data migration b - revert back to previous save point, perhaps previous question s - stop and save changes (splits migration into multiple) q - quit without saving changes h or ? - print help did you create object type 'default::Bar'? [y,n,l,c,i,b,s,q,?] insert query> UPDATE User SET { format := <Format>'f1' }; did you create object type 'default::Bar'? [y,n,l,c,i,b,s,q,?]
-
In this case each query is added as separate savepoint, so it's easy to rollback
-
You can poke the data same way:
did you create object type 'default::Bar'? [y,n,l,c,i,b,s,q,?] insert query> SELECT 1+1; {2} # Read-only query, not recorded did you create object type 'default::Bar'? [y,n,l,c,i,b,s,q,?]
Since we already have RFC1004 implemented, we can:
a) skip adding read-only queries to the migration b) disallow transaction and configuration queries (DDLs are allowed, the problem is that migration transactions are also DDL, so "COMMIT MIGRATION" would work, but it's not a big problem I think)
-
We need to ask confirmation before writing migration:
did you create object type 'default::Spam'? [y,n,l,c,i,b,s,q,?] yes Migration is complete. Proceed creating file? [y,c,i,b,q,?] Created tests/migrations/db2/migrations/00001.edgeql, id: m1puqocioek7ruyi55htuvibjiqixtwi2r4lkajtl22luwnmr4erca
-
This also means that when creating an empty migration, we don't fail right away, but allow inserting manual statements:
No schema changes detected. [i,q,?] insert query> SELECT 1+1; # Read-only query, not recorded No schema changes detected. [i,q,?] insert query> UPDATE User SET { version := .version+1 }; Migration is complete. Proceed creating file? [y,c,i,b,q,?]
-
As this mechanism essentially allows inserting custom DDL too, we might allow that in case server fails:
Server could not figure out migration with your answers. You can rollback an operation or few (press `b`) and try different answers, or write DDL manually (press `i`). Failed to create migration. [c,i,b,s,q,?]
All looks reasonable and useful to me, except
You can poke the data same way:
You can't, because until the commands in the migration block are actually applied to the SQL schema by COMMIT MIGRATION
you cannot refer to any of the schema you've just modified, and using the pre-migration schema for read-only queries would be very confusing.