Analyze Rails apps and provide upgrade assessments
Add this skill
npx mdskills install sickn33/skill-rails-upgradeComprehensive Rails upgrade workflow with safe file merging and multi-version analysis
1---2name: skill-rails-upgrade3description: "Analyze Rails apps and provide upgrade assessments"4source: "https://github.com/robzolkos/skill-rails-upgrade"5risk: safe6---78## When to Use This Skill910Analyze Rails apps and provide upgrade assessments1112Use this skill when working with analyze rails apps and provide upgrade assessments.13# Rails Upgrade Analyzer1415Analyze the current Rails application and provide a comprehensive upgrade assessment with selective file merging.1617## Step 1: Verify Rails Application1819Check that we're in a Rails application by looking for these files:20- `Gemfile` (must exist and contain 'rails')21- `config/application.rb` (Rails application config)22- `config/environment.rb` (Rails environment)2324If any of these are missing or don't indicate a Rails app, stop and inform the user this doesn't appear to be a Rails application.2526## Step 2: Get Current Rails Version2728Extract the current Rails version from:291. First, check `Gemfile.lock` for the exact installed version (look for `rails (x.y.z)`)302. If not found, check `Gemfile` for the version constraint3132Report the exact current version (e.g., `7.1.3`).3334## Step 3: Find Latest Rails Version3536Use the GitHub CLI to fetch the latest Rails release:3738```bash39gh api repos/rails/rails/releases/latest --jq '.tag_name'40```4142This returns the latest stable version tag (e.g., `v8.0.1`). Strip the 'v' prefix for comparison.4344Also check recent tags to understand the release landscape:4546```bash47gh api repos/rails/rails/tags --jq '.[0:10] | .[].name'48```4950## Step 4: Determine Upgrade Type5152Compare current and latest versions to classify the upgrade:5354- **Patch upgrade**: Same major.minor, different patch (e.g., 7.1.3 → 7.1.5)55- **Minor upgrade**: Same major, different minor (e.g., 7.1.3 → 7.2.0)56- **Major upgrade**: Different major version (e.g., 7.1.3 → 8.0.0)5758## Step 5: Fetch Upgrade Guide5960Use WebFetch to get the official Rails upgrade guide:6162URL: `https://guides.rubyonrails.org/upgrading_ruby_on_rails.html`6364Look for sections relevant to the version jump. The guide is organized by target version with sections like:65- "Upgrading from Rails X.Y to Rails X.Z"66- Breaking changes67- Deprecation warnings68- Configuration changes69- Required migrations7071Extract and summarize the relevant sections for the user's specific upgrade path.7273## Step 6: Fetch Rails Diff7475Use WebFetch to get the diff between versions from railsdiff.org:7677URL: `https://railsdiff.org/{current_version}/{target_version}`7879For example: `https://railsdiff.org/7.1.3/8.0.0`8081This shows:82- Changes to default configuration files83- New files that need to be added84- Modified initializers85- Updated dependencies86- Changes to bin/ scripts8788Summarize the key file changes.8990## Step 7: Check JavaScript Dependencies9192Rails applications often include JavaScript packages that should be updated alongside Rails. Check for and report on these dependencies.9394### 7.1: Identify JS Package Manager9596Check which package manager the app uses:9798```bash99# Check for package.json (npm/yarn)100ls package.json 2>/dev/null101102# Check for importmap (Rails 7+)103ls config/importmap.rb 2>/dev/null104```105106### 7.2: Check Rails-Related JS Packages107108If `package.json` exists, check for these Rails-related packages:109110```bash111# Extract current versions of Rails-related packages112cat package.json | grep -E '"@hotwired/|"@rails/|"stimulus"|"turbo-rails"' || echo "No Rails JS packages found"113```114115**Key packages to check:**116117| Package | Purpose | Version Alignment |118|---------|---------|-------------------|119| `@hotwired/turbo-rails` | Turbo Drive/Frames/Streams | Should match Rails version era |120| `@hotwired/stimulus` | Stimulus JS framework | Generally stable across Rails versions |121| `@rails/actioncable` | WebSocket support | Should match Rails version |122| `@rails/activestorage` | Direct uploads | Should match Rails version |123| `@rails/actiontext` | Rich text editing | Should match Rails version |124| `@rails/request.js` | Rails UJS replacement | Should match Rails version era |125126### 7.3: Check for Updates127128For npm/yarn projects, check for available updates:129130```bash131# Using npm132npm outdated @hotwired/turbo-rails @hotwired/stimulus @rails/actioncable @rails/activestorage 2>/dev/null133134# Or check latest versions directly135npm view @hotwired/turbo-rails version 2>/dev/null136npm view @rails/actioncable version 2>/dev/null137```138139### 7.4: Check Importmap Pins (if applicable)140141If the app uses importmap-rails, check `config/importmap.rb` for pinned versions:142143```bash144cat config/importmap.rb | grep -E 'pin.*turbo|pin.*stimulus|pin.*@rails' || echo "No importmap pins found"145```146147To update importmap pins:148```bash149bin/importmap pin @hotwired/turbo-rails150bin/importmap pin @hotwired/stimulus151```152153### 7.5: JS Dependency Summary154155Include in the upgrade summary:156157```158### JavaScript Dependencies159160**Package Manager**: [npm/yarn/importmap/none]161162| Package | Current | Latest | Action |163|---------|---------|--------|--------|164| @hotwired/turbo-rails | 8.0.4 | 8.0.12 | Update recommended |165| @rails/actioncable | 7.1.0 | 8.0.0 | Update with Rails |166| ... | ... | ... | ... |167168**Recommended JS Updates:**169- Run `npm update @hotwired/turbo-rails` (or yarn equivalent)170- Run `npm update @rails/actioncable @rails/activestorage` to match Rails version171```172173---174175## Step 8: Generate Upgrade Summary176177Provide a comprehensive summary including all findings from Steps 1-7:178179### Version Information180- Current version: X.Y.Z181- Latest version: A.B.C182- Upgrade type: [Patch/Minor/Major]183184### Upgrade Complexity Assessment185186Rate the upgrade as **Small**, **Medium**, or **Large** based on:187188| Factor | Small | Medium | Large |189|--------|-------|--------|-------|190| Version jump | Patch only | Minor version | Major version |191| Breaking changes | None | Few, well-documented | Many, significant |192| Config changes | Minimal | Moderate | Extensive |193| Deprecations | None active | Some to address | Many requiring refactoring |194| Dependencies | Compatible | Some updates needed | Major dependency updates |195196### Key Changes to Address197198List the most important changes the user needs to handle:1991. Configuration file updates2002. Deprecated methods/features to update2013. New required dependencies2024. Database migrations needed2035. Breaking API changes204205### Recommended Upgrade Steps2062071. Update test suite and ensure passing2082. Review deprecation warnings in current version2093. Update Gemfile with new Rails version2104. Run `bundle update rails`2115. Update JavaScript dependencies (see JS Dependencies section)2126. **DO NOT run `rails app:update` directly** - use the selective merge process below2137. Run database migrations2148. Run test suite2159. Review and update deprecated code216217### Resources218219- Rails Upgrade Guide: https://guides.rubyonrails.org/upgrading_ruby_on_rails.html220- Rails Diff: https://railsdiff.org/{current}/{target}221- Release Notes: https://github.com/rails/rails/releases/tag/v{target}222223---224225226## When to Use This Skill227228Analyze Rails apps and provide upgrade assessments229230Use this skill when working with analyze rails apps and provide upgrade assessments.231## Step 9: Selective File Update (replaces `rails app:update`)232233**IMPORTANT:** Do NOT run `rails app:update` as it overwrites files without considering local customizations. Instead, follow this selective merge process:234235### 9.1: Detect Local Customizations236237Before any upgrade, identify files with local customizations:238239```bash240# Check for uncommitted changes241git status242243# List config files that differ from a fresh Rails app244# These are the files we need to be careful with245git diff HEAD --name-only -- config/ bin/ public/246```247248Create a mental list of files in these categories:249- **Custom config files**: Files with project-specific settings (i18n, mailer, etc.)250- **Modified bin scripts**: Scripts with custom behavior (bin/dev with foreman, etc.)251- **Standard files**: Files that haven't been customized252253### 9.2: Analyze Required Changes from Railsdiff254255Based on the railsdiff output from Step 6, categorize each changed file:256257| Category | Action | Example |258|----------|--------|---------|259| **New files** | Create directly | `config/initializers/new_framework_defaults_X_Y.rb` |260| **Unchanged locally** | Safe to overwrite | `public/404.html` (if not customized) |261| **Customized locally** | Manual merge needed | `config/application.rb`, `bin/dev` |262| **Comment-only changes** | Usually skip | Minor comment updates in config files |263264### 9.3: Create Upgrade Plan265266Present the user with a clear upgrade plan:267268```269## Upgrade Plan: Rails X.Y.Z → A.B.C270271### New Files (will be created):272- config/initializers/new_framework_defaults_A_B.rb273- bin/ci (new CI script)274275### Safe to Update (no local customizations):276- public/400.html277- public/404.html278- public/500.html279280### Needs Manual Merge (local customizations detected):281- config/application.rb282 └─ Local: i18n configuration283 └─ Rails: [describe new Rails changes if any]284285- config/environments/development.rb286 └─ Local: letter_opener mailer config287 └─ Rails: [describe new Rails changes]288289- bin/dev290 └─ Local: foreman + Procfile.dev setup291 └─ Rails: changed to simple ruby script292293### Skip (comment-only or irrelevant changes):294- config/puma.rb (only comment changes)295```296297### 9.4: Execute Upgrade Plan298299After user confirms the plan:300301#### For New Files:302Create them directly using the content from railsdiff or by extracting from a fresh Rails app:303304```bash305# Generate a temporary fresh Rails app to extract new files306cd /tmp && rails new rails_template --skip-git --skip-bundle307# Then copy needed files308```309310Or use the Rails generator for specific files:311```bash312bin/rails app:update:configs # Only updates config files, still interactive313```314315#### For Safe Updates:316Overwrite these files as they have no local customizations.317318#### For Manual Merges:319For each file needing merge, show the user:3203211. **Current local version** (their customizations)3222. **New Rails default** (from railsdiff)3233. **Suggested merged version** that:324 - Keeps all local customizations325 - Adds only essential new Rails functionality326 - Removes deprecated settings327328Example merge for `config/application.rb`:329```ruby330# KEEP local customizations:331config.i18n.available_locales = [:de, :en]332config.i18n.default_locale = :de333config.i18n.fallbacks = [:en]334335# ADD new Rails 8.1 settings if needed:336# (usually none required - new defaults come via new_framework_defaults file)337```338339### 9.5: Handle Active Storage Migrations340341After file updates, run any new migrations:342343```bash344bin/rails db:migrate345```346347Check for new migrations that were added:348```bash349ls -la db/migrate/ | tail -10350```351352### 9.6: Verify Upgrade353354After completing the merge:3553561. Start the Rails server and check for errors:357 ```bash358 bin/dev # or bin/rails server359 ```3603612. Check the Rails console:362 ```bash363 bin/rails console364 ```3653663. Run the test suite:367 ```bash368 bin/rails test369 ```3703714. Review deprecation warnings in logs372373---374375## Step 10: Finalize Framework Defaults376377After verifying the app works:3783791. Review `config/initializers/new_framework_defaults_X_Y.rb`3802. Enable each new default one by one, testing after each3813. Once all defaults are enabled and tested, update `config/application.rb`:382 ```ruby383 config.load_defaults X.Y # Update to new version384 ```3854. Delete the `new_framework_defaults_X_Y.rb` file386387---388389390## When to Use This Skill391392Analyze Rails apps and provide upgrade assessments393394Use this skill when working with analyze rails apps and provide upgrade assessments.395## Error Handling396397- If `gh` CLI is not authenticated, instruct the user to run `gh auth login`398- If railsdiff.org doesn't have the exact versions, try with major.minor.0 versions399- If the app is already on the latest version, congratulate the user and note any upcoming releases400- If local customizations would be lost, ALWAYS stop and show the user what would be overwritten before proceeding401402## Key Principles4034041. **Never overwrite without checking** - Always check for local customizations first4052. **Preserve user intent** - Local customizations exist for a reason4063. **Minimal changes** - Only add what's necessary for the new Rails version4074. **Transparency** - Show the user exactly what will change before doing it4085. **Reversibility** - User should be able to `git checkout` to restore if needed409
Full transparency — inspect the skill content before installing.