ruby-on-railsrubyahoy

How to uninstall ahoy gem


Ahoy gem is filling my database uncomfortably, so I was looking to uninstall it. Obviously, gem uninstall ahoy-matey. But afterward the gem was still there, along with all the models and etc. How can I delete its existence from my app, without breaking the app?


Solution

  • I'm going to make some assumptions about your app to answer this question. Feel free to provide additional information if this answer does not apply to you.

    gem uninstall ahoy-matey isn't going to do anything for your app because the gem is called ahoy_matey. Uninstalling the gem requires gem uninstall ahoy_matey.

    Even then, this has no effect your app. Rails apps use bundler to manage gems through a Gemfile, so removing the gem from your app would require editing the Gemfile to remove the reference to ahoy_matey, then running bundle install to update your gems.

    But this still won't remove it from your app. I assume that you are using a standard git workflow and that before installing ahoy you were working from a clean branch with no uncommitted changes, and that after you installed and configured ahoy you committed all those changes. You need to go back to your git commit history to see what changes were made to your app and begin undoing them.

    Looking at the installation instructions, you probably had to run these commands:

    rails generate ahoy:install
    rails db:migrate
    

    The generator will have created a couple of models for you, an initializer, and a database migration. Removing these isn't as simple as "just delete the files." You will need to write a migration to drop these tables from your database while maintaining your database's migration history. Figuring out what tables to drop will require reviewing what the original migrations did that were added by the gem.

    After you have written and run your migration you can then remove any models and initializers that were created by the gem. Finally, you can run your application's test suite to ensure the app works properly before starting it and validating it works the way you expect.