[Feature Proposal]: Introduce UI for running one-off scripts and data migrations found in the /script folder

Why

Based on many conversations over the years regarding one-off scripts best practices, I want to introduce a new UI experience for the /script folder. Much akin to the wonderful MailerPreviews UI.

What

This feature would implement several items:

  1. Display a listing of all available scripts that can be run
  2. Show an individual script page
    1. Enable manual running of the script
    2. Enable viewing of script source code
    3. Enable ephemeral script output results
    4. Enable form submission disable state to prevent individual users from re-running scripts
    5. Enable cache-based lock for currently running scripts to avoid multiplicative effects from multiple users
  3. Provide a configuration to constrain script generated routes behind host implemented authorization (using: Rails Routing from the Outside In — Ruby on Rails Guides )
    1. The configuration would allow authorized multi-environment running of scripts

If there is interest in a script UI, I’ve got a spike in progress for implementation and would love to get feedback on it.

Benefits

  • Makes scripts more visible and gives a dedicated UI to run them
  • Allows team members without rails console permission to run available scripts
  • Follows along with established pattern of MailerPreviews in terms of routing and style
  • Leans into making scripts a default location for one-off scripts
  • Can run in any environment
  • Prevents multiplicative effect (via lock) of two users trying to run the same script at the same time

Downsides

  • Can run in any environment (benefit as well) which means that the auth logic needs to be solid
  • Uses cache for storing output and locking script (would have short expires at)
  • No script stopping mechanism (no different than running it directly in CI though)
    • Good use-case for using maintenance tasks instead

Discussions:

  1. Is there any "official" way to organize one-off scripts?
  2. Approaches to data migration on Rails applications

Take a look at https://github.com/Shopify/maintenance_tasks

It does what you want.

Rafael França Rails Core Team Member

2 Likes

Thanks for the quick reply and the suggestion for maintenance_tasks. I really like the gem and have begun scratching the surface on it.