Sha256: 12358fc7ad90e156c4ed6a46031780e02babc1acac7183c9a55ce0c007bdfe27

Contents?: true

Size: 924 Bytes

Versions: 42

Compression:

Stored size: 924 Bytes

Contents

# frozen_string_literal: true

require 'thredded/base_migration'

class UpgradeThreddedV011ToV012 < Thredded::BaseMigration
  def up
    FriendlyId::Slug.transaction do
      FriendlyId::Slug.where(sluggable_type: 'Thredded::Topic').where(
        slug: FriendlyId::Slug.group(:slug).having('count(id) > 1').select(:slug)
      ).group_by(&:slug).each_value do |slugs|
        slugs.from(1).each(&:delete)
      end
      FriendlyId::Slug.where(sluggable_type: 'Thredded::Topic')
        .update_all(scope: nil)
    end
    Thredded::Topic.all.find_each do |topic|
      # re-generate the slug
      topic.title_will_change!
      topic.save!
    end
    remove_index :thredded_topics, name: :index_thredded_topics_on_messageboard_id_and_slug
    add_index :thredded_topics, [:slug], name: :index_thredded_topics_on_slug, unique: true
  end

  def down
    fail ActiveRecord::MigrationError::IrreversibleMigration
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

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