Sha256: 251a3c4edbbfc6cf9ef97d39b8cc0694685118586142bb3637bc194440b8aba4
Contents?: true
Size: 748 Bytes
Versions: 106
Compression:
Stored size: 748 Bytes
Contents
class AddPositionToPages < ActiveRecord::Migration[5.2] def self.up unless column_exists? :pages, :position add_column :pages, :position, :integer Page.reset_column_information say_with_time("Putting all pages in a default order...") do ActiveRecord::Base.record_timestamps = false Page.where(parent_id: nil).each do |p| put_children_into_list(p) end ActiveRecord::Base.record_timestamps = true end end end def self.down remove_column :pages, :position end def self.put_children_into_list(page) page.children.order("title asc").each_with_index do |pg, idx| pg.update_attribute('position', idx + 1) put_children_into_list(pg) end end end
Version data entries
106 entries across 106 versions & 1 rubygems