You might want to take a look at <a href="https:&#x2F;&#x2F;github.com&#x2F;pboling&#x2F;flag_shih_tzu" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pboling&#x2F;flag_shih_tzu</a>, which does all of that and a lot more, like adding database scopes.