Sha256: 8baeffde78b32896c6fb70904e56761e4f791ed3654dbdfa6b4b3f0adc9fa1ed

Contents?: true

Size: 974 Bytes

Versions: 74

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true

class MakeBlogpostsAuthorsPolymorphics < ActiveRecord::Migration[5.2]
  class Post < ApplicationRecord
    self.table_name = :decidim_blogs_posts

    include Decidim::HasComponent
  end

  def change
    add_column :decidim_blogs_posts, :decidim_author_type, :string

    Post.reset_column_information
    Post.find_each do |post|
      if post.decidim_author_id.present?
        post.decidim_author_type = "Decidim::UserBaseEntity"
      else
        post.decidim_author_id = post.organization.id
        post.decidim_author_type = "Decidim::Organization"
      end
      post.save!
    end

    add_index :decidim_blogs_posts,
              [:decidim_author_id, :decidim_author_type],
              name: "index_decidim_blogs_posts_on_decidim_author"
    change_column_null :decidim_blogs_posts, :decidim_author_id, false
    change_column_null :decidim_blogs_posts, :decidim_author_type, false

    Post.reset_column_information
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
decidim-blogs-0.29.1 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.28.4 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.27.9 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.29.0 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.28.3 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.27.8 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.29.0.rc4 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.29.0.rc3 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.29.0.rc2 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.29.0.rc1 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.28.2 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.27.7 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.28.1 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.27.6 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.26.10 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.26.9 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.28.0 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.27.5 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.28.0.rc5 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb
decidim-blogs-0.28.0.rc4 db/migrate/20181017084519_make_blogposts_authors_polymorphics.rb