Reducing migration friction during development #4254
Replies: 6 comments 9 replies
-
FWIW I experimented with creating a standalone light-weight self-contained executable that does exactly that. It's doable. cc @elprans |
Beta Was this translation helpful? Give feedback.
-
|
I think the biggest pain in "reducing migration friction during development" is not generating migration files "headlessly". It's the fact that to run the app, migrations must be applied to the DB. So if users do it with the current workflow they will end up with tens of migrations during single feature development. We need live schema update without producing migration files. Or with keeping track of which schema files can be safe-fully squashed (which is not possible in the general way, but we might develop some subset of it that might work for most users). Note that with squashing there is quite a big chance that something will be committed prematurely or squashed more than needed (and recovery is painful). So I'm looking forward for "no-artifact live schema update" as DX (even if internally it's done by squashing). |
Beta Was this translation helpful? Give feedback.
-
|
Another problem with "headless" mode, is: which version of headless EdgeDB should be used for migrations/codegen? Is it specified in |
Beta Was this translation helpful? Give feedback.
-
|
My two cents on this:
I don't think generating query builder code is a pain point here. It's one command with no prompts. Of course this would be done behind a flag. |
Beta Was this translation helpful? Give feedback.
-
|
Another thing to account for is: test driven development (TDD). Currently, you can do |
Beta Was this translation helpful? Give feedback.
-
On "2 Applying schema changes without creating migration files"I think we can and should collapse the notion of We add |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When developing an application and rapidly iterating on the schema,
Below are a number of non-mutually-exclusive proposals for alleviating this.
1 Headless EdgeDB
Provide a way to run EdgeDB or a partial version of it in a "headless" way. Code generation commands can spin up a "headless" instance on demand instead of connecting to a project-linked instance.
Altneratively, this could be a standalone Python package that parses SDL into an introspectable form, no backend SQL required.
Regarding code generation
Once something like this is implemented, all code generation tools should be modified to take advantage of the "headless mode". In this scenario, the schema file(s) would act as the source of truth for the codegen tool.
To prepare users for this and minimize transition difficult, we should consider modifying all codegen tools to verify that the database is in sync with the latest schema files. This can be achieved by checking the result of
start migration to.2 Applying schema changes without creating migration files
Alternatives:
--unstaged--schema-onlyThis creates and applies a migration in one step, considering the following:
migration create --yolobelow)If revision history in the files and database diverge, the command does the following:
ALTER MIGRATION(see below)Note: (4) can return empty diff, this means rebase is simpler.
3 Migration squashing
The following command is used to "switch from" dev mode and provide committable
migration:
Aternatives:
--from-dev-modeThis mode fails if schema in the database != schema in the files.
By default
migration createwill ask interactively whether you want to squash if it detects, that schema matches but there are multiple extra revisions in the database.Internally this works in the following steps:
START MIGRATION TO ..., and verify diff is zeroSTART MIGRATION TOand do regular (preferably interactive) migration process, storing the migration fileALTER MIGRATION ..on the original databaseNew EdgeQL syntax:
This works along the lines of the following:
<parent-name>from migrations recorded in the database<name>Note: this operation never changes schema and data
Generally this allows full rebase process for migrations, but I'd reserve this only for
migration apply --dev-modeandmigration create --squashin 3.0.4 Branching
This proposal involves introducing a concept of a branch. Branches are a schema-only concept. Creating a branch does not copy any data.
In practice, each "branch" is a new database with a UUID as the name.
This requires some notion of a "checked out branch". By default the checkout out branch/database is
default. This is tracked inedgedb.toml.To check out a new branch:
This will:
defaultagainst itdbschema/migrations/newbranchcontainingmetadata.tomlfile to track the parent revision:edgedb.tomlto setcurrent_branchto"newbranch"From this point on, all created migration files are written to
dbschema/migrations/newbranch.Once the user is satisfied with their changes, they can squash them back into
default.All migration files in
dbschema/migrations/newbranchare squashed into a single migration file and written toschema/migrations.newbranchmigration files, or it could be more clever (e.g. if a property goes from optional to required then back to optional, it can drop thedefaulthas changesThen
dbschema/migrations/newbranch/metadata.tomlis updated to indicate that the branch is "fully merged".This is roughly analogous to
merge --squashconceptually. Once a branch is merged back into its parent, it shouldn't be possible to add more migrations in that branch. I don't think an equivalent ofrebaseis practical or useful?5 "Live mode"
Basically "live mode" is
edgedb migration apply --dev-modewith watch. But there are nuances:edgedb database wipemust be done before.So to make it more more convenient another meta command should be added:
A way to synchronize the database with the latest version of the schema files without generating a migration file. Likely will involve clearing the database contents and possibly auto-running a seed script/fixture afterwards.
Alternative names:
edgedb liveedgedb monitor6
migration create --yoloPer geldata/gel-cli#796.
Changelog:
migration push->migration apply --dev-mode(it should not store file, and keep number of commands at minimum)watchcommandBeta Was this translation helpful? Give feedback.
All reactions