biff
biff copied to clipboard
Add db fixtures
Some feedback:
I would have liked to see an example in the template for seeding the db with an edn file or something. Not a high priority feature but I think most projects will want to do something like that
Seems reasonable to me, and will only take a minute.
I'll wait until at least one more person requests this
To whatever degree you still care about this--I am requesting it. I ended up writing most of my seed data by hand and interactively entering it via the REPL, but it is a hassle.
I'm also potentially open to Pull Requesting this, once I get a little bit more familiar with Biff.
I still care about it! I'll bump it up in priority a bit since you mention it.
I'm thinking of at least three "levels" of stuff that could be done, I'm curious on which would have the most impact for you:
- There could be an edn file somewhere where you can manually enter data, and then Biff takes care of transacting it into the database*
- There could be a command which would export the DB's current contents into the EDN file, so you can generate seed data by playing around with the app instead of typing it all manually
- We could use Malli's value generation to auto-generate the EDN file from your app's schema
1 and 2 would be pretty easy. 3 might not be that bad either, I've just never used the value generation stuff before so it's a bit of an unknown for me.
Also let me know if you envision this working in some other way--I'm not sure how other frameworks handle this, and I don't really use seed data myself (which is why I haven't gotten around to implementing helpers for it).
*e.g. perhaps in dev, Biff checks if the database is empty, and then transacts the seed data if so. If you update the seed data, then you just delete the dev database (rm -r storage/xtdb) and restart the app.
Thanks for the sponsorship by the way 🙂.
1 is probably most immediately helpful to my use-case--even though I can also write EDN by hand, it's also not that hard to export my generated data to an EDN file. 2 sounds nice, but I likely wouldn't use it that much.
In the long term, I think 3 is probably the most exciting, but I think 1 already gives so much flexibility that it may not be necessary. You could theoretically already generate Malli schemas and write them out to an EDN file.
And you're welcome! I'm working on deploying my first Biff app right now, hoping to make some money off of it someday, so I thought it'd be only right to pay it forward.
Sounds good! By the way, once your app is launched let me know if you'd like to be listed under projects built with Biff--it'd be nice to get some things on there built by people other than me ha ha.
I've added a minimal version of this to the example app: https://github.com/jacobobryant/biff/commit/9b6c8e8a087a1a5414dac24d3844f862a5c46335. For existing projects you can copy and paste the contents of that commit. I was thinking about having Biff load the fixtures automatically if the database was empty but decided to just go with this slightly more manual/explicit approach.
In connection with this, I also added a new feature to Biff's transaction format: "temporary IDs". Any :db.id/* keywords will get replaced with random UUIDs, which makes it possible to define the fixtures transaction completely in EDN without having to hard-code any UUIDs. As such, you'll need to upgrade Biff for this to work (set the sha in deps.edn to "9b6c8e8a087a1a5414dac24d3844f862a5c46335").
I'll go ahead and close this issue, but feel free to reopen if there's more stuff that would be helpful for you. (Same for anyone else reading this.)