mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 09:53:42 +08:00
5f64fd0a21
Introduce new patterns for direct sql that are safe and fast. MiniSql is not prone to memory bloat that can happen with direct PG usage. It also has an extremely fast materializer and very a convenient API - DB.exec(sql, *params) => runs sql returns row count - DB.query(sql, *params) => runs sql returns usable objects (not a hash) - DB.query_hash(sql, *params) => runs sql returns an array of hashes - DB.query_single(sql, *params) => runs sql and returns a flat one dimensional array - DB.build(sql) => returns a sql builder See more at: https://github.com/discourse/mini_sql
24 lines
1017 B
Ruby
24 lines
1017 B
Ruby
class GoogleOpenidDefaultHasChanged < ActiveRecord::Migration[4.2]
|
|
def up
|
|
users_count_query = DB.query_single("SELECT count(*) FROM users")
|
|
if users_count_query.first.to_i > 1
|
|
# This is an existing site.
|
|
result = DB.query_single("SELECT count(*) FROM site_settings WHERE name = 'enable_google_logins'")
|
|
if result.first.to_i == 0
|
|
# 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
|
|
|
|
# Don't enable the new Google setting on an existing site.
|
|
result = DB.query_single("SELECT count(*) FROM site_settings WHERE name = 'enable_google_oauth2_logins'")
|
|
if result.first.to_i == 0
|
|
execute "INSERT INTO site_settings (name, data_type, value, created_at, updated_at) VALUES ('enable_google_oauth2_logins', 5, 'f', now(), now())"
|
|
end
|
|
end
|
|
end
|
|
|
|
def down
|
|
# No need to undo.
|
|
end
|
|
end
|