From d24e0e72a76a3f12a29687b4cf6b206a83969913 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 11 Sep 2019 12:21:21 +0200 Subject: [PATCH] Correctly create new flipper flags --- config/initializers/flipper.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index f50fb3a8f..dee6e022e 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -16,12 +16,10 @@ end # this will immediately migrate the default features to be controlled. def setup_features(features) features.each do |feature| - if Flipper.exist?(feature) - return + if !Flipper.exist?(feature) + # Disable feature by default + Flipper.disable(feature) end - - # Disable feature by default - Flipper.disable(feature) end end @@ -39,8 +37,15 @@ features = [ :xray ] +def database_exists? + ActiveRecord::Base.connection + true +rescue ActiveRecord::NoDatabaseError + false +end + ActiveSupport.on_load(:active_record) do - if ActiveRecord::Base.connection.data_source_exists? 'flipper_features' + if database_exists? && ActiveRecord::Base.connection.data_source_exists?('flipper_features') setup_features(features) end end