December 22, 2015

Posted by John

Tagged flipper

Older: Flipper: Insanely Easy Feature Flipping

Newer: Flipper Preloading

Flipping ActiveRecord

Originally, I did not like the idea of an ActiveRecord adapter for Flipper. I work on GitHub.com day to day, so everything I do has to be extremely performant. Using ActiveRecord for something like this felt like way too much overhead.

In fact, at GitHub, we use a custom adapter for Flipper built on good old raw SQL. Not only that, but we also use a memcache adapter which wraps the pure SQL adapter to avoid hitting MySQL most of the time. The memcache wrapper (at the time of this writing) works similar to the memoizing adapter that is included with Flipper (for those that are curious).

Over time, a few good options came out for using Flipper with ActiveRecord and they changed my mind. I realized that not every application is GitHub.com. Some applications value ease of integration over performance. I even wrote my own ActiveRecord adapter for SpeakerDeck, which is what I am now including in the core flipper repo (but available as a separate gem).

Installation

Drop the gem in your Gemfile:

gem "flipper-active_record"

Generate the migration:

rails g flipper:active_record

Usage

require 'flipper/adapters/active_record'
adapter = Flipper::Adapters::ActiveRecord.new
flipper = Flipper.new(adapter)
# profit...

From there, you use flipper the same as you would with any of the previously supported adapters. Internally, all features are stored in a flipper_features table and all gate related values are stored in a flipper_gates table. You can see more about the internals in the examples.

Conclusion

As of Flipper 0.7.3, you can now flip features with the easy and comfort of ActiveRecord and the peace of mind that as new AR versions are released, your flipper adapter will be updated and ready to go.

Happy flipping and happy holidays!

1 Comment

  1. Flipper is a new thing for me. I am also using Github for last five years. Anyways nice and useful information.

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.

Projects

Flipper
Release your software more often with fewer problems.
Flip your features.