Sha256: 26550932ac9b72e55f09ef570589e86b9226cd8df6b276c3c97c787a296cc0ce

Contents?: true

Size: 1021 Bytes

Versions: 30

Compression:

Stored size: 1021 Bytes

Contents

class AddPermalink < ActiveRecord::Migration
  class BareArticle < ActiveRecord::Base
    include BareMigration

    def stripped_title(title)
      # this is a copynpaste of the routine in article.rb
      # so the one in article.rb can change w/o breaking this.
      self.title.gsub(/<[^>]*>/,'').to_url
    end
  end

  class BareCategory < ActiveRecord::Base
    include BareMigration

    def stripped_name
      # copynpaste from category.rb
      self.name.to_url
    end
  end

  def self.up
    STDERR.puts "Adding categories permalink"
    modify_tables_and_update([:add_column, BareCategory, :permalink, :string],
                             [:add_index,  BareCategory, :permalink]) do
      BareCategory.find_and_update {|c| c.permalink ||= c.stripped_name }
      BareArticle.find_and_update  {|a| a.permalink ||= a.stripped_title }
    end
  end


  def self.down
    STDERR.puts "Removing categories permalink"
    remove_index :categories, :permalink
    remove_column :categories, :permalink
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
typo-5.5 db/migrate/007_add_permalink.rb
typo-5.4.4 db/migrate/007_add_permalink.rb
typo-5.4.3 db/migrate/007_add_permalink.rb
typo-5.4.2 db/migrate/007_add_permalink.rb
typo-5.4.1 db/migrate/007_add_permalink.rb
typo-5.4 db/migrate/007_add_permalink.rb
typo-3.99.0 db/migrate/007_add_permalink.rb
typo-3.99.2 db/migrate/007_add_permalink.rb
typo-3.99.3 db/migrate/007_add_permalink.rb
typo-3.99.1 db/migrate/007_add_permalink.rb
typo-4.0.0 db/migrate/007_add_permalink.rb
typo-4.0.1 db/migrate/007_add_permalink.rb
typo-4.0.2 db/migrate/007_add_permalink.rb
typo-3.99.4 db/migrate/007_add_permalink.rb
typo-4.0.3 db/migrate/007_add_permalink.rb
typo-4.1.1 db/migrate/007_add_permalink.rb
typo-5.0.1 db/migrate/007_add_permalink.rb
typo-5.0.2 db/migrate/007_add_permalink.rb
typo-4.1 db/migrate/007_add_permalink.rb
typo-5.0.3.98.1 db/migrate/007_add_permalink.rb