Sha256: 13a9405052d51b1a8e726527810b266fcaf759891abb58804d0cf75b6b6b52e4

Contents?: true

Size: 865 Bytes

Versions: 50

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

class AddScopesToInitiativesVotes < ActiveRecord::Migration[5.2]
  class InitiativeVote < ApplicationRecord
    self.table_name = :decidim_initiatives_votes
    belongs_to :initiative, foreign_key: "decidim_initiative_id", class_name: "Initiative"
  end

  class Initiative < ApplicationRecord
    self.table_name = :decidim_initiatives
    belongs_to :scoped_type, class_name: "InitiativesTypeScope"
  end

  class InitiativesTypeScope < ApplicationRecord
    self.table_name = :decidim_initiatives_type_scopes
  end

  def change
    add_column :decidim_initiatives_votes, :decidim_scope_id, :integer

    InitiativeVote.reset_column_information

    InitiativeVote.includes(initiative: :scoped_type).find_each do |vote|
      vote.decidim_scope_id = vote.initiative.scoped_type.decidim_scopes_id
      vote.save!
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

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