Sha256: 5f59a68b7a64b0282a189f057939c93449d9b76c9596789a4a284a713e5e28f3

Contents?: true

Size: 894 Bytes

Versions: 14

Compression:

Stored size: 894 Bytes

Contents

# frozen_string_literal: true

class DropsCategoriesForTags < ActiveRecord::Migration[4.2]
  class Categorization < ActiveRecord::Base
    belongs_to :article
    belongs_to :category
  end

  class Category < ActiveRecord::Base
    has_many :categorizations
    has_many :articles, through: :categorizations
  end

  def up
    # First, we migrate categories into tags
    Category.find_each do |cat|
      # Does a tag with the same permalink exist?
      tag = Tag.find_or_create_by(name: cat.permalink) do |tg|
        tg.display_name = cat.name
      end

      Redirect.create(from_path: "category/#{cat.permalink}",
                      to_path: File.join(Blog.first.base_url, "tag", tag.name))
      cat.articles.each do |article|
        article.tags << tag
        article.save
      end
    end

    drop_table :categorizations
    drop_table :categories
  end

  def down; end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
publify_core-10.0.2 db/migrate/115_drops_categories_for_tags.rb
publify_core-10.0.1 db/migrate/115_drops_categories_for_tags.rb
publify_core-10.0.0 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.10 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.9 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.8 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.7 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.6 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.5 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.4 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.3 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.2 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.1 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.2.0 db/migrate/115_drops_categories_for_tags.rb