Sha256: 0a2d65405ad4c0b3395567c44e44b62788e22e32f2ab9a1273bfa7ff0c4d1d89

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

class AddOrganizationAsAuthorToDebates < ActiveRecord::Migration[5.2]
  class Debate < ApplicationRecord
    self.table_name = :decidim_debates_debates
    include Decidim::HasComponent
  end

  class User < ApplicationRecord
    self.table_name = :decidim_users
  end

  def change
    add_column :decidim_debates_debates, :decidim_author_type, :string

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

    add_index :decidim_debates_debates,
              [:decidim_author_id, :decidim_author_type],
              name: "index_decidim_debates_debates_on_decidim_author"
    change_column_null :decidim_debates_debates, :decidim_author_id, false
    change_column_null :decidim_debates_debates, :decidim_author_type, false
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-debates-0.27.3 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.2 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.1 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.0 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.0.rc2 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.0.rc1 db/migrate/20181016132850_add_organization_as_author_to_debates.rb