Sha256: 6f65fc4be721ac172cf6be564b3b3d3ba69853ff9d2f3ba5cc1b99fe9ac60e7b

Contents?: true

Size: 1.06 KB

Versions: 50

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

class AllowMultipleOfflineVotes < ActiveRecord::Migration[5.2]
  class InitiativesTypeScope < ApplicationRecord
    self.table_name = :decidim_initiatives_type_scopes
  end

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

  def change
    rename_column :decidim_initiatives, :offline_votes, :old_offline_votes
    add_column :decidim_initiatives, :offline_votes, :jsonb, default: {}

    Initiative.reset_column_information

    Initiative.includes(:scoped_type).find_each do |initiative|
      scope_key = initiative.scoped_type.decidim_scopes_id || "global"

      offline_votes = {
        scope_key => initiative.old_offline_votes.to_i,
        "total" => initiative.old_offline_votes.to_i
      }

      # rubocop:disable Rails/SkipsModelValidations
      initiative.update_column(:offline_votes, offline_votes)
      # rubocop:enable Rails/SkipsModelValidations
    end

    remove_column :decidim_initiatives, :old_offline_votes
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

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