diff --git a/db/fixtures/009_users.rb b/db/fixtures/009_users.rb index e6c7486b9..4c5f11875 100644 --- a/db/fixtures/009_users.rb +++ b/db/fixtures/009_users.rb @@ -27,6 +27,40 @@ UserOption.where(user_id: -1).update_all( Group.user_trust_level_change!(-1, TrustLevel[4]) +# 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 + WHERE table_name = 'users' AND column_name = 'enable_quoting' + ) AND + name = 'AllowDefaultsOnUsersTable' AND + 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 + ].each do |column| + User.exec_sql("ALTER TABLE users DROP column #{column}") + end + + end +end + # User for the smoke tests if ENV["SMOKE"] == "1" smoke_user = User.seed do |u| diff --git a/db/migrate/20160225050318_allow_defaults_on_users_table.rb b/db/migrate/20160225050318_allow_defaults_on_users_table.rb new file mode 100644 index 000000000..999e275fd --- /dev/null +++ b/db/migrate/20160225050318_allow_defaults_on_users_table.rb @@ -0,0 +1,10 @@ +class AllowDefaultsOnUsersTable < ActiveRecord::Migration + def up + # we need to temporarily change table a bit to ensure we can insert new records + change_column :users, :email_digests, :boolean, null: false, default: true + change_column :users, :external_links_in_new_tab, :boolean, null: false, default: false + end + + def down + end +end