diff --git a/config/app.yml b/config/app.yml index f6ac215d9..eff724611 100644 --- a/config/app.yml +++ b/config/app.yml @@ -1,5 +1,5 @@ shared: &shared - version: '1.5.3' + version: '1.6.1' development: <<: *shared diff --git a/db/migrate/20200709145000_remove_multiple_feature_flags.rb b/db/migrate/20200709145000_remove_multiple_feature_flags.rb new file mode 100644 index 000000000..82a9ede27 --- /dev/null +++ b/db/migrate/20200709145000_remove_multiple_feature_flags.rb @@ -0,0 +1,21 @@ +class RemoveMultipleFeatureFlags < ActiveRecord::Migration[6.0] + def change + current_config = InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').last + InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').where.not(id: current_config.id).destroy_all + ConfigLoader.new.process + update_existing_accounts + end + + def update_existing_accounts + feature_config = InstallationConfig.find_by(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS') + facebook_config = feature_config.value.find { |value| value['name'] == 'channel_facebook' } + twitter_config = feature_config.value.find { |value| value['name'] == 'channel_twitter' } + Account.find_in_batches do |account_batch| + account_batch.each do |account| + account.enable_features(['channel_facebook']) if facebook_config['enabled'] + account.enable_features(['channel_twitter']) if twitter_config['enabled'] + account.save! + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b6337dbcd..b5f354e5d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_07_04_173104) do +ActiveRecord::Schema.define(version: 2020_07_09_145000) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" diff --git a/lib/config_loader.rb b/lib/config_loader.rb index a313bb190..e880d3dd1 100644 --- a/lib/config_loader.rb +++ b/lib/config_loader.rb @@ -74,11 +74,11 @@ class ConfigLoader def compare_and_save_feature(config) features = if @reconcile_only_new # leave the existing feature flag values as it is and add new feature flags with default values - (account_features + config.value).uniq { |h| h['name'] } + (config.value + account_features).uniq { |h| h['name'] } else # update the existing feature flag values with default values and add new feature flags with default values - (config.value + account_features).uniq { |h| h['name'] } + (account_features + config.value).uniq { |h| h['name'] } end - save_as_new_config({ name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS', value: features }) + config.update({ name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS', value: features }) end end