Sha256: cb8a4a1432cfd3e8cbfcf0eeea3b000b0beff53df6861b4594acdc0377e70895

Contents?: true

Size: 1.2 KB

Versions: 42

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'thredded/base_migration'

class UpgradeV05ToV06 < Thredded::BaseMigration
  def up
    add_column :thredded_messageboards, :last_topic_id, column_type(:thredded_topics, :id)
    Thredded::Messageboard.reset_column_information
    Thredded::Messageboard.all.each do |messageboard|
      messageboard.update_column :last_topic_id, messageboard.topics.order(updated_at: :desc, id: :desc).first.try(:id)
    end
    change_column_null :thredded_posts, :postable_id, false
    # Allow null on user_id and last_user_id because users can get deleted.
    change_column_null :thredded_topics, :user_id, true
    change_column_null :thredded_topics, :last_user_id, true
    change_column_null :thredded_private_topics, :user_id, true
    change_column_null :thredded_private_topics, :last_user_id, true
  end

  def down
    change_column_null :thredded_private_topics, :last_user_id, false
    change_column_null :thredded_private_topics, :user_id, false
    change_column_null :thredded_topics, :last_user_id, false
    change_column_null :thredded_topics, :user_id, false
    change_column_null :thredded_posts, :postable_id, true
    remove_column :thredded_messageboards, :last_topic_id
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
thredded-1.1.0 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-1.0.1 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-1.0.0 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.16 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.15 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.14 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.13 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.12 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.11 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.10 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.9 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.8 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.7 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.6 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.5 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.4 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.3 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.1 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.16.0 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb
thredded-0.15.5 db/upgrade_migrations/20160611094616_upgrade_v0_5_to_v0_6.rb