geldata / geldata/gel-cli

Data migrations in interactive mode

Open
#218 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
175
Forks
32
PR merge metrics
No merged PRs in 30d

Description

https://github.com/edgedb/edgedb/pull/2138

1. 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 := 'f1' };
did you create object type 'default::Bar'? [y,n,l,c,i,b,s,q,?]
```
2. In this case each query is added as separate savepoint, so it's easy to rollback
3. 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)

4. 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
```
5. 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,?]
```
6. 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,?]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.