2013-09-06 04:03:30 -04:00
|
|
|
# kind of odd, but we need it, we also need to nuke usage of User from inside migrations
|
|
|
|
# very poor form
|
2014-05-06 09:41:59 -04:00
|
|
|
user = User.find_by("id <> -1 and username_lower = 'system'")
|
2013-09-06 00:07:23 -04:00
|
|
|
if user
|
2013-09-06 03:28:37 -04:00
|
|
|
user.username = UserNameSuggester.suggest("system")
|
2013-09-06 00:07:23 -04:00
|
|
|
user.save
|
|
|
|
end
|
|
|
|
|
|
|
|
User.seed do |u|
|
|
|
|
u.id = -1
|
2013-09-06 03:28:37 -04:00
|
|
|
u.name = "system"
|
|
|
|
u.username = "system"
|
|
|
|
u.username_lower = "system"
|
|
|
|
u.email = "no_email"
|
2013-09-06 00:07:23 -04:00
|
|
|
u.password = SecureRandom.hex
|
|
|
|
u.active = true
|
|
|
|
u.admin = true
|
|
|
|
u.moderator = true
|
|
|
|
u.approved = true
|
2014-09-05 01:20:39 -04:00
|
|
|
u.trust_level = TrustLevel[4]
|
2013-09-06 00:07:23 -04:00
|
|
|
end
|
2014-06-16 20:46:30 -04:00
|
|
|
|
2016-02-16 23:46:19 -05:00
|
|
|
UserOption.where(user_id: -1).update_all(
|
|
|
|
email_private_messages: false,
|
|
|
|
email_direct: false
|
|
|
|
)
|
|
|
|
|
2015-07-27 05:07:42 -04:00
|
|
|
Group.user_trust_level_change!(-1, TrustLevel[4])
|
|
|
|
|
2016-02-17 02:08:05 -05:00
|
|
|
# 60 minutes after our migration runs we need to exectue this code...
|
|
|
|
duration = Rails.env.production? ? 60 : 0
|
|
|
|
if User.exec_sql("SELECT 1 FROM schema_migration_details
|
|
|
|
WHERE EXISTS(
|
|
|
|
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
2017-02-07 09:39:41 -05:00
|
|
|
WHERE table_schema = 'public' AND table_name = 'users'
|
|
|
|
AND column_name = 'auth_token'
|
2016-02-17 02:08:05 -05:00
|
|
|
) AND
|
2017-02-07 09:39:41 -05:00
|
|
|
name = 'AddUserAuthTokens' AND
|
2016-02-17 02:08:05 -05:00
|
|
|
created_at < (current_timestamp at time zone 'UTC' - interval '#{duration} minutes')
|
|
|
|
").to_a.length > 0
|
|
|
|
|
|
|
|
|
|
|
|
User.transaction do
|
|
|
|
STDERR.puts "Removing superflous user columns!"
|
|
|
|
%w[
|
|
|
|
email_always
|
|
|
|
mailing_list_mode
|
|
|
|
email_digests
|
|
|
|
email_direct
|
|
|
|
email_private_messages
|
|
|
|
external_links_in_new_tab
|
|
|
|
enable_quoting
|
|
|
|
dynamic_favicon
|
|
|
|
disable_jump_reply
|
|
|
|
edit_history_public
|
|
|
|
automatically_unpin_topics
|
|
|
|
digest_after_days
|
2016-02-18 00:57:22 -05:00
|
|
|
auto_track_topics_after_msecs
|
|
|
|
new_topic_duration_minutes
|
|
|
|
last_redirected_to_top_at
|
2017-02-07 09:39:41 -05:00
|
|
|
auth_token
|
|
|
|
auth_token_updated_at
|
2016-02-18 00:57:22 -05:00
|
|
|
].each do |column|
|
2016-02-17 05:02:44 -05:00
|
|
|
User.exec_sql("ALTER TABLE users DROP column IF EXISTS #{column}")
|
2016-02-17 02:08:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-27 05:07:42 -04:00
|
|
|
# User for the smoke tests
|
|
|
|
if ENV["SMOKE"] == "1"
|
|
|
|
smoke_user = User.seed do |u|
|
|
|
|
u.id = 0
|
|
|
|
u.name = "smoke_user"
|
|
|
|
u.username = "smoke_user"
|
|
|
|
u.username_lower = "smoke_user"
|
|
|
|
u.email = "smoke_user@discourse.org"
|
|
|
|
u.password = "P4ssw0rd"
|
|
|
|
u.active = true
|
|
|
|
u.approved = true
|
|
|
|
u.approved_at = Time.now
|
|
|
|
u.trust_level = TrustLevel[3]
|
|
|
|
end.first
|
|
|
|
|
2016-02-17 05:57:06 -05:00
|
|
|
UserOption.where(user_id: smoke_user.id).update_all(
|
|
|
|
email_direct: false,
|
|
|
|
email_digests: false,
|
|
|
|
email_private_messages: false,
|
|
|
|
)
|
|
|
|
|
|
|
|
EmailToken.where(user_id: smoke_user.id).update_all(confirmed: true)
|
2015-07-27 05:07:42 -04:00
|
|
|
end
|
2016-02-16 23:46:19 -05:00
|
|
|
|