Data migration script upon deploy
Is there any mechanism for setting values into newly created fields on models upon deploying or pushing to a new environment?
The Gadget AI agent recommended creating a new global action for this - just wasn't sure if there was anything baked in.
9 Replies
There are default values for model fields but I assume that wont fit your use case.
There isnt any build in Gadget functions for this otherwise
gotcha
@[Gadget] Antoine just wanted to double check - there's no concept of data migrations in gadget....?
No, there is no such thing as a built in data migration in Gadget at the moment
Related feature request here: https://discord.com/channels/836317518595096598/1329813785673859094/1329813785673859094
This is a simple problem for Gadget but if they enable this via say CSV import will they get a gazillion support requests from people ignoring the database relationships and structures. Or will they end up with convoluted code for edge cases. I wrote my own and hid it in an admin route. Allows me to import any CSV as long as the headers exactly match the model and strips out any records with null values for required fields. Ai did nearly all the work. Only 8 models and <100 records per model. 4 hours work roughly inculding the UI.
Went ahead and just built out a little migrations cli that I'm tying into my github deploy workflows.
neat! What's your core use case? backfilling default values?
yeah pretty much
also just like adding a shop field to a model where it was missing previously and then populating it kinda thing
Right. I typically create a simple global action in gadget and just run it right after deploy. But I don't have any advanced github deploy workflow either 😀