<commit_before>Flipper.configure do |config|
  config.default do
    Flipper.new(Flipper::Adapters::ActiveRecord.new)
  end
end

Flipper.register('Administrateurs') do |user|
  user.administrateur_id.present?
end
Flipper.register('Instructeurs') do |user|
  user.instructeur_id.present?
end

# 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.
def setup_features(features)
  features.each do |feature|
    if Flipper.exist?(feature)
      return
    end

    # Disable feature by default
    Flipper.disable(feature)
  end
end

# A list of features to be deployed on first push
features = [
  :administrateur_champ_integer_number,
  :administrateur_web_hook,
  :insee_api_v3,
  :instructeur_bypass_email_login_token,
  :instructeur_download_as_zip,
  :maintenance_mode,
  :mini_profiler,
  :operation_log_serialize_subject,
  :pre_maintenance_mode,
  :xray
]

ActiveSupport.on_load(:active_record) do
  if ActiveRecord::Base.connection.data_source_exists? 'flipper_features'
    setup_features(features)
  end
end<commit_msg>Correctly create new flipper flags<commit_after>Flipper.configure do |config|
  config.default do
    Flipper.new(Flipper::Adapters::ActiveRecord.new)
  end
end

Flipper.register('Administrateurs') do |user|
  user.administrateur_id.present?
end
Flipper.register('Instructeurs') do |user|
  user.instructeur_id.present?
end

# 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.
def setup_features(features)
  features.each do |feature|
    if !Flipper.exist?(feature)
      # Disable feature by default
      Flipper.disable(feature)
    end
  end
end

# A list of features to be deployed on first push
features = [
  :administrateur_champ_integer_number,
  :administrateur_web_hook,
  :insee_api_v3,
  :instructeur_bypass_email_login_token,
  :instructeur_download_as_zip,
  :maintenance_mode,
  :mini_profiler,
  :operation_log_serialize_subject,
  :pre_maintenance_mode,
  :xray
]

def database_exists?
  ActiveRecord::Base.connection
  true
rescue ActiveRecord::NoDatabaseError
  false
end

ActiveSupport.on_load(:active_record) do
  if database_exists? && ActiveRecord::Base.connection.data_source_exists?('flipper_features')
    setup_features(features)
  end
end
{'fraction_non_alphanumeric': 0.07603960396039604, 'fraction_numerical': 0.0007920792079207921, 'mean_word_length': 5.221674876847291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '99487', 'n_tokens_mistral': 800, 'n_tokens_neox': 815, 'n_words': 206}