Sha256: a1ada1854ea62461e583ecf0566488677f85b8ed305889014f4ed9f8310e5ab4

Contents?: true

Size: 1023 Bytes

Versions: 19

Compression:

Stored size: 1023 Bytes

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.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

19 entries across 19 versions & 1 rubygems

Version Path
decidim-debates-0.29.1 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.28.4 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.9 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.29.0 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.28.3 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.8 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.29.0.rc4 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.29.0.rc3 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.29.0.rc2 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.29.0.rc1 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.28.2 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.7 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.28.1 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.6 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.28.0 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.5 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.28.0.rc5 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.28.0.rc4 db/migrate/20181016132850_add_organization_as_author_to_debates.rb
decidim-debates-0.27.4 db/migrate/20181016132850_add_organization_as_author_to_debates.rb