Seeding/fixtures/migration hooks #4288
Replies: 7 comments 11 replies
-
|
Starting with just random comments, on what's described:
|
Beta Was this translation helpful? Give feedback.
-
|
Some roadmap as I would see it: Step 1
Each script is processed by Step 2Then we can extend this into any binaries that are in the directory. So I think it should also work on windows, by associating Step 3The problem with (Step 2) is compiled languages, like Go and Rust (and probably Java, C# too). Direct symlink (e.g. to Or: Alternatively we can also use some cross-platform shell like nushell for scripts instead of toml. Notes
|
Beta Was this translation helpful? Give feedback.
-
|
Another idea is that we can parametherize And then: |
Beta Was this translation helpful? Give feedback.
-
|
Also we should consider setting |
Beta Was this translation helpful? Give feedback.
-
|
@colinhacks what do we do with |
Beta Was this translation helpful? Give feedback.
-
|
I like pretty much all ideas in this thread (and |
Beta Was this translation helpful? Give feedback.
-
|
For "independent fixtures" big question is how to find out which fixtures are already applied and which ones are new, so that Can we have some |
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.
-
Various ideas relating to fixtures: how they are specified and how/when they are applied.
Single seed command
An initial decision to make is whether fixtures/hooks need to be associated with a particular revision. I like the idea of a single project-wide seed that evolves as the project develops, instead of a series of smaller per-migration seeding steps.
Prisma allows users to provide an arbitrary seed command in their
package.json. Usually this is something likenode seed.js. Whenever users runprisma db seed,prisma migrate reset, orprisma migrate dev(a dev only equivalent ofedgedb migrate) the seed script is executed.We could do something similar, where a seed command is specified in
edgedb.toml. This opens up some options.edgedb migration seed: drops all data in the database and re-runs the seed scriptedgedb migration sync: this opens the door to potentially destructive migration commands likeedgedb migration syncto clear the database, edit the migration history, and re-seed the db.Squash friendliness
Another reason to consider a single project-wide fixture is to accommodate any future migration squashing functionality. If each individual migration can be associated with a seed script, it's not clear squashing would work.
Independent fixtures (per Paul's comment)
dbschema/fixtures.edgeqlfiles are supported out of the gate, plus files (.js, .py) with an appropriate shebangThis may involve a new
edgedb fixturecommand groupThe command above would execute the files in
dbschema/fixtures/benchmarks.Internally we have:
This records each fixture applied. So that
edgedb fixture applywill only apply new fixtures, and warn when hash of the file changed.Migration-coupled fixtures
Client-driven
Under this proposal, users can provide a custom "migration executor" script. That performs additional actions before after the migration itself. The content of the migration script itself can be provided in an environment variable.
.tomlconfigurationFixture-related metadata can be supplied in a per-migration
.tomlfile that lives next to the.edgeqlfile. For instance,dbschema/migrations/00005.edgeqlwould correspond todbschema/migrations/00005.toml. This.tomlfile could contain seed data, EdgeQL queries, or a set of pre-post migration commands.The appeal of this is that the seed file can be anything: a script, an EdgeQL file, etc. Users are responsible for managing any dependencies (
node, etc) required to execute seed scripts.Application
These fixtures/scripts will be executed by the CLI during
edgedb migrate.There could be some mechanism for categorizing fixtures. For instance, some fixtures could be marked as development-only and others as production fixtures (which act as data migrations). Which fixtures to apply would be specified when applying migrations:
edgedb migrate --fixtures, dev,prod.Atomicity
In this proposal, fixtures are treated as "data migrations" and should be applied atomically alongside the migration files. To do so, we need some way for seed scripts and the CLI to share a transaction. There are a couple ways this can be achieved.
_EDGEDB_TRANSACTION_ID. The underscore is to indicate that this is intended as an internal API. The clients & CLI would read this variable and respect it if defined. When defined, creating additional transactions should be disallowed.EDGEDB_DSNor similar). We would instruct users to callcreate_clientwithout explicit parameters or transaction blocks.Additional ideas/considerations
Data-only dumps
It would be cool if users could dump the contents (data only, not schema) of their database into a file (probably an
.edgeqlscript) that could then be used for seeding. Potential workflow:edgedb migration create-seeddbschema/scripts/<revision-hash>.dump00005.edgeql), creates00005.tomlfile (if necessary), and sets the value ofrun_queriesto["<revision-hash>.dump"]Parameterized
*.edgeqlfilesPer #4288 (comment)
Changelog:
sys::Fixtureto "Independen Fixtures" sectionBeta Was this translation helpful? Give feedback.
All reactions