Chore: Add migration for feature flags (#1024)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose 2020-07-10 00:09:40 +05:30 committed by GitHub
parent 929575f11a
commit e8994165ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View file

@ -1,5 +1,5 @@
shared: &shared
version: '1.5.3'
version: '1.6.1'
development:
<<: *shared

View file

@ -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

View file

@ -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"

View file

@ -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