2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
class GoogleOpenidDefaultHasChanged < ActiveRecord::Migration[4.2]
|
2014-05-21 18:19:40 -04:00
|
|
|
def up
|
2018-06-19 02:13:14 -04:00
|
|
|
users_count_query = DB.query_single("SELECT count(*) FROM users")
|
|
|
|
if users_count_query.first.to_i > 1
|
2014-05-21 19:40:59 -04:00
|
|
|
# This is an existing site.
|
2018-06-19 02:13:14 -04:00
|
|
|
result =
|
|
|
|
DB.query_single("SELECT count(*) FROM site_settings WHERE name = 'enable_google_logins'")
|
|
|
|
if result.first.to_i == 0
|
2014-05-21 19:40:59 -04:00
|
|
|
# The old default was true, so add a row to keep it that way.
|
|
|
|
execute "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('enable_google_logins', 5, 't', now(), now())"
|
|
|
|
end
|
2014-05-22 11:41:31 -04:00
|
|
|
|
|
|
|
# Don't enable the new Google setting on an existing site.
|
2018-06-19 02:13:14 -04:00
|
|
|
result =
|
|
|
|
DB.query_single(
|
|
|
|
"SELECT count(*) FROM site_settings WHERE name = 'enable_google_oauth2_logins'",
|
|
|
|
)
|
|
|
|
if result.first.to_i == 0
|
2014-05-22 11:41:31 -04:00
|
|
|
execute "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('enable_google_oauth2_logins', 5, 'f', now(), now())"
|
|
|
|
end
|
2014-05-21 18:19:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# No need to undo.
|
|
|
|
end
|
|
|
|
end
|