2019-07-04 12:36:17 +02:00
|
|
|
# This setup is primarily for first deployment, because consequently
|
|
|
|
# we can add new features from the Web UI. However when the new DB is created
|
|
|
|
# this will immediately migrate the default features to be controlled.
|
2024-03-02 16:37:03 +01:00
|
|
|
#
|
|
|
|
require 'flipper/adapters/active_record'
|
|
|
|
require 'flipper/adapters/active_support_cache_store'
|
|
|
|
|
2019-07-04 12:36:17 +02:00
|
|
|
def setup_features(features)
|
2024-03-02 16:33:25 +01:00
|
|
|
existing = Flipper.preload(features).map { _1.name.to_sym }
|
|
|
|
missing = features - existing
|
|
|
|
|
|
|
|
missing.each do |feature|
|
|
|
|
# Feature is disabled by default
|
|
|
|
Flipper.add(feature.to_s)
|
2019-07-04 12:36:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A list of features to be deployed on first push
|
|
|
|
features = [
|
|
|
|
:administrateur_web_hook,
|
2021-09-08 16:15:04 +02:00
|
|
|
:api_particulier,
|
2024-03-02 16:33:25 +01:00
|
|
|
:attestation_v2,
|
|
|
|
:blocking_pending_correction,
|
|
|
|
:cojo_type_de_champ,
|
2021-03-03 18:20:34 +01:00
|
|
|
:dossier_pdf_vide,
|
2024-03-02 16:33:25 +01:00
|
|
|
:engagement_juridique_type_de_champ,
|
|
|
|
:export_order_by_revision,
|
2024-04-09 15:12:21 +02:00
|
|
|
:export_template,
|
2024-03-02 16:33:25 +01:00
|
|
|
:expression_reguliere_type_de_champ,
|
2024-04-22 20:55:13 +02:00
|
|
|
:gallery_demande,
|
2023-06-14 12:35:43 +02:00
|
|
|
:groupe_instructeur_api_hack,
|
2024-03-02 16:33:25 +01:00
|
|
|
:hide_instructeur_email,
|
2023-12-18 12:32:27 +01:00
|
|
|
:sva,
|
2024-04-22 10:47:47 +02:00
|
|
|
:switch_domain,
|
|
|
|
:champ_update_by_stable_id
|
2019-07-04 12:36:17 +02:00
|
|
|
]
|
|
|
|
|
2019-09-11 12:21:21 +02:00
|
|
|
def database_exists?
|
|
|
|
ActiveRecord::Base.connection
|
|
|
|
true
|
2023-08-31 12:12:49 +02:00
|
|
|
rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError, PG::ConnectionBad
|
2019-09-11 12:21:21 +02:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2019-07-04 12:36:17 +02:00
|
|
|
ActiveSupport.on_load(:active_record) do
|
2019-09-11 12:21:21 +02:00
|
|
|
if database_exists? && ActiveRecord::Base.connection.data_source_exists?('flipper_features')
|
2019-07-04 12:36:17 +02:00
|
|
|
setup_features(features)
|
|
|
|
end
|
|
|
|
end
|
2024-03-02 16:33:25 +01:00
|
|
|
|
2024-03-02 16:37:03 +01:00
|
|
|
Flipper.configure do |config|
|
|
|
|
config.adapter do
|
|
|
|
Flipper::Adapters::ActiveSupportCacheStore.new(
|
|
|
|
Flipper::Adapters::ActiveRecord.new,
|
|
|
|
ActiveSupport::Cache::MemoryStore.new,
|
|
|
|
expires_in: 10.seconds
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-02 16:33:25 +01:00
|
|
|
Rails.application.configure do
|
2024-03-03 00:13:55 +01:00
|
|
|
# don't preload features for /assets/* but do for everything else
|
|
|
|
config.flipper.preload = -> (request) { !request.path.start_with?('/assets/', '/ping') }
|
2024-03-02 16:33:25 +01:00
|
|
|
config.flipper.strict = Rails.env.development?
|
|
|
|
end
|