Sha256: ace2f22bafca7447bb187ac7779fb95a8f88629db3a564427ef09a8d7ba480a2

Contents?: true

Size: 1.9 KB

Versions: 42

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

require 'thredded/base_migration'

class UpgradeV06ToV07 < Thredded::BaseMigration
  def up
    Thredded::MessageboardGroup.transaction do
      Thredded::MessageboardGroup.where(
        name: Thredded::MessageboardGroup.group(:name).having('count(id) > 1').select(:name)
      ).group_by(&:name).each_value do |messageboard_groups|
        messageboard_groups.from(1).each_with_index do |messageboard_group, i|
          messageboard_group.update!(name: "#{messageboard_group.name}-#{i + 1}")
        end
      end
    end

    add_index :thredded_messageboard_groups,
              :name,
              unique: true,
              name: :index_thredded_messageboard_group_on_name

    add_column :thredded_topics, :last_post_at, :datetime
    add_column :thredded_private_topics, :last_post_at, :datetime
    # update existing values to pretty accurate match
    Thredded::Topic.update_all('last_post_at = updated_at')
    Thredded::PrivateTopic.update_all('last_post_at = updated_at')

    add_column :thredded_messageboards, :position, :integer
    Thredded::Messageboard.reset_column_information
    Thredded::Messageboard.all.each { |m| m.update_column(:position, m.created_at.to_i) }
    change_column :thredded_messageboards, :position, :integer, null: false

    add_column :thredded_messageboard_groups, :position, :integer
    Thredded::MessageboardGroup.reset_column_information
    Thredded::MessageboardGroup.all.each { |mg| mg.update_column(:position, mg.created_at.to_i) }
    change_column :thredded_messageboard_groups, :position, :integer, null: false
  end

  def down
    remove_index :thredded_messageboard_groups, name: :index_thredded_messageboard_group_on_name
    remove_column :thredded_topics, :last_post_at
    remove_column :thredded_private_topics, :last_post_at
    remove_column :thredded_messageboards, :position
    remove_column :thredded_messageboard_groups, :position
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

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