2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
class DisableExternalAuthsByDefault < ActiveRecord::Migration[4.2]
|
2014-06-04 23:35:18 +08:00
|
|
|
|
|
|
|
def enable_setting_if_default(name)
|
2018-06-19 14:13:14 +08:00
|
|
|
result = DB.query_single("SELECT count(*) count FROM site_settings WHERE name = '#{name}'")
|
|
|
|
if result.first.to_i == 0
|
2014-06-04 23:35:18 +08:00
|
|
|
execute "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('#{name}', 5, 't', now(), now())"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def up
|
2018-06-19 14:13:14 +08:00
|
|
|
users_count_query = DB.query_single("SELECT count(*) FROM users")
|
|
|
|
if users_count_query.first.to_i > 1
|
2014-06-04 23:35:18 +08:00
|
|
|
# existing site, so keep settings as they are
|
|
|
|
enable_setting_if_default 'enable_yahoo_logins'
|
|
|
|
enable_setting_if_default 'enable_google_oauth2_logins'
|
|
|
|
enable_setting_if_default 'enable_twitter_logins'
|
|
|
|
enable_setting_if_default 'enable_facebook_logins'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# No need to undo
|
|
|
|
end
|
|
|
|
end
|