Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we have a conventional namespace for data migration rake tasks? #391

Open
eoinkelly opened this issue Oct 21, 2022 · 4 comments
Open
Labels
discuss Discussion required ready for dev

Comments

@eoinkelly
Copy link
Contributor

Most apps I have worked on need a "one time only" rake tasks which perform some kind of data migration of production data. I have a strong preference for migrating data in a rake task and only changing database structure in migrations (whenever possible, sometimes you have to use migrations).

Each time I have had bikeshedding conversations with the teams on those projects about what namespace we should put that task in: none, temp:, one_off:, data_migration: etc. These conversations seem like quite low value so I think it would be good if this template expressed a preference by creating a file under lib/tasks with a comment encouraging devs to put this kind of task in the file.

For example:

# lib/tasks/data_migration.rake

# Use this namespace for data migration tasks e.g. a one-time data migration of
# production data. 
#
# You may want to periodically delete old tasks from this namespace if they
# don't provide ongoing value to the developers.
# 
namespace :data_migration do
  # desc "Update user data because ...."
  # task 2022_03_update_users: :environment do
  # end
end
@eoinkelly eoinkelly changed the title Should we have a conventional namespace for data migration rake tasks Should we have a conventional namespace for data migration rake tasks? Oct 21, 2022
@eoinkelly eoinkelly added the question Further information is requested label Oct 21, 2022
@robotdana
Copy link
Contributor

i'd love to compare our preferences for one-time-only data migrations, to me they go in db/migrate and should be written with sql directly and not rely on models or activerecord

@robotdana
Copy link
Contributor

robotdana commented May 5, 2023

but this example with the timestamp in the name and the desc and data_migration as the namespace feels good if we must use rake tasks

@robotdana
Copy link
Contributor

if this data migration can be rolled back that's another reason to put in db/migrate

we'll probably make this a confluence/notion page rather than part of rails-template as there are pros and cons to the various approaches and they suit different circumstances

@eoinkelly
Copy link
Contributor Author

Another approach from my current project is a ./one-off-scripts directory in project root which contains Ruby files run via bundle exec rails runner ./one-off-scripts/do_thing.rb

I like that this makes the nature of the scripts a bit more obvious and makes it clearer that future dev can delete this script once it has run

@eoinkelly eoinkelly added discuss Discussion required and removed question Further information is requested labels Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Discussion required ready for dev
Projects
None yet
Development

No branches or pull requests

2 participants