lucky_migrator
lucky_migrator copied to clipboard
Allow running something in a block when adding a required field to an existing table
This issue (https://github.com/luckyframework/lucky_migrator/issues/12) is very helpful, but sometimes filling the table with a static value is not ideal.
For example, you may want to add a slug to blog posts, in which case you'd want to generate the slug for each post and then save it.
We should make another version of adding a required field that accepts a block:
alter :posts do
add slug : String do
# Will set all the slugs
generate_slugs_for_posts
end
# The field will be marked as required (NOT NULL) once the block has finished
end
@mikeeus Would you be interested in trying this one?
This looks like an interesting feature to build. Can you give me any pointers on how to start?
Can the user run anything in the block? For example do we just add yield
to the add
macro and execute anything?
@mikeeus I'd love to give some pointers. I think the block should only be accepted when adding a required (non ?
column) when altering a table. For everything else, it should not be added.
The block could be anything the user wants. Does that help? Let me know if you need any more info!