Sha256: ef94d444d679725e9b166c652eae7fcee22c85a5bae9ad739a156e1e5198648a

Contents?: true

Size: 813 Bytes

Versions: 108

Compression:

Stored size: 813 Bytes

Contents

class ChangePostElementsToVersions < ActiveRecord::Migration
  def up
    rename_column :pulitzer_content_elements, :post_id, :version_id
    rename_column :pulitzer_post_tags, :post_id, :version_id
    Pulitzer::ContentElement.reset_column_information
    Pulitzer::PostTag.reset_column_information

    # Clone post content elements and clone tags, and assign them to the new version
    Pulitzer::Post.find_each do |post|
      version = post.create_preview_version
      Pulitzer::ContentElement.where(version_id: post.id).update_all(version_id: version.id)
      Pulitzer::PostTag.where(version_id: post.id).update_all(version_id: version.id)
    end
  end

  def down
    rename_column :pulitzer_content_elements, :version_id, :post_id
    rename_column :pulitzer_post_tags, :version_id, :post_id
  end
end

Version data entries

108 entries across 106 versions & 1 rubygems

Version Path
pulitzer-0.1.9 db/migrate/20151029220558_change_post_elements_to_versions.rb
pulitzer-0.1.8 db/migrate/20151029220558_change_post_elements_to_versions.rb
pulitzer-0.1.7 db/migrate/20151029220558_change_post_elements_to_versions.rb
pulitzer-0.1.6 db/migrate/20151029220558_change_post_elements_to_versions.rb
pulitzer-0.1.5 db/migrate/20151029220558_change_post_elements_to_versions.rb
pulitzer-0.1.4 db/migrate/20151029220558_change_post_elements_to_versions.rb
pulitzer-0.1.3 db/migrate/20151029220558_change_post_elements_to_versions.rb
pulitzer-0.1.2 db/migrate/20151029220558_change_post_elements_to_versions.rb