Chore: Add migration for feature flags (#1024)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
shared: &shared
|
shared: &shared
|
||||||
version: '1.5.3'
|
version: '1.6.1'
|
||||||
|
|
||||||
development:
|
development:
|
||||||
<<: *shared
|
<<: *shared
|
||||||
|
|||||||
21
db/migrate/20200709145000_remove_multiple_feature_flags.rb
Normal file
21
db/migrate/20200709145000_remove_multiple_feature_flags.rb
Normal 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
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_stat_statements"
|
enable_extension "pg_stat_statements"
|
||||||
|
|||||||
@@ -74,11 +74,11 @@ class ConfigLoader
|
|||||||
def compare_and_save_feature(config)
|
def compare_and_save_feature(config)
|
||||||
features = if @reconcile_only_new
|
features = if @reconcile_only_new
|
||||||
# leave the existing feature flag values as it is and add new feature flags with default values
|
# 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
|
else
|
||||||
# update the existing feature flag values with default values and add new feature flags with default values
|
# 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
|
end
|
||||||
save_as_new_config({ name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS', value: features })
|
config.update({ name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS', value: features })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user