Sha256: 735737f97a5852656826d938f732cea8aa26d34fea6d0c8a055e54f737cf0501
Contents?: true
Size: 771 Bytes
Versions: 15
Compression:
Stored size: 771 Bytes
Contents
class AddNestingToArticles < ActiveRecord::Migration def self.up remove_column :contents, :position add_column :contents, :parent_id, :integer add_column :contents, :lft, :integer, :default => 0, :null => false add_column :contents, :rgt, :integer, :default => 0, :null => false # initialize lft, rgt, and parent_ids in all articles for each section Article.all.group_by(&:section).each do |section, articles| articles.each_with_index do |a, i| a.parent_id = nil a.lft = i*2+1 a.rgt = i*2+2 a.save end end end def self.down add_column :contents, :position, :integer remove_column :contents, :parent_id remove_column :contents, :lft remove_column :contents, :rgt end end
Version data entries
15 entries across 15 versions & 2 rubygems